OK, I’ve rewritten your script:
pc.script.attribute('anchoTexto', 'number', 0.0, {
displayName: "Ancho"
});
pc.script.attribute('altoTexto','number', 0.0, {
displayName: "Alto"
});
pc.script.attribute('reglones','number', 0.0, {
displayName: "Reglones"
});
pc.script.attribute('separador','number', 0.0, {
displayName: "Separación entre reglones",
min: 0,
max:2
});
pc.script.attribute('colorTexto','string', 'no funciona todavía', {
displayName: "Color"
});
pc.script.attribute('tamanoTexto','string', '70px', {
displayName: "tamaño"
});
pc.script.attribute('fuente','enumeration', 'Verdana', {
displayName: "Fuente",
enumerations: [{
name: "Verdana",
value: 'Verdana'
},
{
name: "Arial",
value: 'Arial'
},
{
name: "Times New Roman",
value: 'Times New Roman'
},
{
name: "Courier New",
value: 'Courier New'
},
{
name: "Serif",
value: 'serif'
},
{
name: "sans-serif",
value: 'sans-serif'
}]
});
pc.script.attribute('variante','enumeration', 'normal', {
displayName: "Variante",
enumerations: [{
name: "Normal",
value: 'normal'
},
{
name: "Small-caps",
value: 'small-caps'
}]
});
pc.script.attribute('estilo','enumeration', 'normal', {
displayName: "Estilo",
enumerations: [{
name: "Normal",
value: 'normal'
},
{
name: "Italic",
value: 'italic'
},
{
name: "Oblicua",
value: 'oblique'
}]
});
pc.script.attribute('peso','enumeration', 'normal', {
displayName: "Peso",
enumerations: [{
name: "Normal",
value: 'normal'
},
{
name: "Bold",
value: 'bold'
},
{
name: "Bolder",
value: 'bolder'
},
{
name: "Lighter",
value: 'lighter'
},
{
name: "100",
value: '100'
},
{
name: "200",
value: '200'
},
{
name: "300",
value: '300'
},
{
name: "400",
value: '400'
},
{
name: "500",
value: '500'
},
{
name: "600",
value: '600'
},
{
name: "700",
value: '700'
},
{
name: "800",
value: '800'
},
{
name: "900",
value: '900'
}]
});
pc.script.create('texto_bocadillo', function (app) {
// Creates a new Text instance
var texto_bocadillo = function (entity) {
this.entity = entity;
};
texto_bocadillo.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.tiempo=0;
this.canvas = document.createElement('canvas');
this.canvas.height = this.altoTexto;
this.canvas.width = this.anchoTexto;
this.context = this.canvas.getContext("2d");
this.texture = new pc.Texture(app.graphicsDevice, {
format: pc.PIXELFORMAT_R8_G8_B8,
autoMipmap: true
});
this.texture.setSource(this.canvas);
this.texture.minFilter = pc.FILTER_LINEAR;
this.texture.magFilter = pc.FILTER_LINEAR;
this.texture.addressU = pc.ADDRESS_REPEAT;
this.texture.addressV = pc.ADDRESS_REPEAT;
this.updateText();
var material = this.entity.model.material;
material.emissive.set(0, 0, 1);
material.emissiveMap = this.texture;
material.emissiveMapTint = true;
material.opacityMap = this.texture;
material.blendType = pc.BLEND_NORMAL;
material.opacity = 1;
material.alphaTest = 0;
material.noFog = true;
material.update();
},
updateText: function () {
var ctx = this.context;
var w = ctx.canvas.width;
var h = ctx.canvas.height;
// Clear the context to transparent
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, w, h);
// Write white text
ctx.textBaseline = 'middle';
ctx.font = this.peso + ' ' + this.tamanoTexto + ' Verdana';
ctx.textAlign = 'center';
ctx.fillStyle = 'white';
ctx.fillText(this.texto, w / 2, h / 2);
// Copy the canvas into the texture
//
this.texture.upload();
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
this.tiempo = this.tiempo + dt;
console.log(this.tiempo);
if(this.tiempo>4)
{
this.texto='Lolailo';
this.updateText();
}
if(this.tiempo>6)
{
this.texto='Prueba2';
this.updateText();
this.tiempo=0;
}
}
};
return texto_bocadillo;
});
I think the problem was your alpha test value. You should set this to 0 to avoid any partially transparent pixels around the text from being discarded in the shader. However, I’ve made a bunch of other improvements. The script uses emissiveMapTint to allow you to color the text whatever color you like. I have also updated the code to only ever create one canvas.