SomeClass.attributes.add('text', {type: 'entity' });
this.text.element._text._text = "WORDS";
what am i doing wrong?
SomeClass.attributes.add('text', {type: 'entity' });
this.text.element._text._text = "WORDS";
what am i doing wrong?
It’s hard to tell without seeing the whole code. Is this a script attached to a Text element? If so, this code works for me:
var TextUpdate = pc.createScript('textUpdate');
// initialize code called once per entity
TextUpdate.prototype.initialize = function() {
};
// update code called every frame
TextUpdate.prototype.update = function(dt) {
if(this.app.keyboard.wasPressed(pc.KEY_SPACE)){
this.entity.element.text = "Hello World!";
}
};
Or is text
an attribute that references a text element? If so, this script works for me:
var TextUpdate2 = pc.createScript('textUpdate2');
TextUpdate2.attributes.add('text', {type: 'entity' });
// initialize code called once per entity
TextUpdate2.prototype.initialize = function() {
};
// update code called every frame
TextUpdate2.prototype.update = function(dt) {
if(this.app.keyboard.wasPressed(pc.KEY_UP)){
this.text.element.text = "Blah!";
}
};
If you can’t find it in the docs a good way to just see what properties are available is to just do:
console.log(this.text.element)
And you should see that you can access the text
property, but also things like spacing
and lineHeight
etc.
The top solution worked perfectly for how I had things set up
ty ty