If you’re using world.addGraphic()
to add the text item, ignore the Entity
itself and store a reference to the text object:
public class MyWorld extends World {
private var txt:Text;
override public function begin():void {
addGraphic(txt = new Text("Hello, World!");
}
override public function update():void {
if (Input.mousePressed) {
txt.text = "Curse your sudden but inevitable betrayal!";
}
}
}
If, on the other hand, your Text
item is embedded inside an Entity
you create directly, simply wrap the call:
public class HudText extends Entity {
private var txt:Text;
public function HudText() {
graphic = txt = new Text("Woo-hoo");
}
/** The text to be displayed. */
public function get text():String { return txt.text; }
public function set text(value:String):void {
txt.text = value;
}
}
public class MyWorld extends World {
private var hud:HudText;
override public function begin():void {
add(hud = new HudText());
}
override public function update():void {
if (Input.mousePressed) {
hud.text = "Curse your sudden but inevitable betrayal!";
}
}
}