Question
how to get a messageField working from a class file?
Hi team,
So I have this code that I have modified to run from the game.js class file.
It runs with no errors and I can trace the text (loading)
BUT - there is no text on the screen when I run it.
Thanks for your help 🙂
class Game
{
constructor(root, lib)
{
this.root = root;
this.stage = this.root.stage;
this.canvas = this.root.canvas;
this.messageField = this.root.messageField;
this.lib = lib;
this.init();
this.keys ={};
}
init(e){
this.player = this.root.player_mc;
const game = this;
document.addEventListener("keydown", (e) => {
console.log(`Key "${e.key}" pressed [event: keydown]`);
this.keys[e.key] = true;
});
document.addEventListener("keyup", (e) => {
console.log(`Key "${e.key}" pressed [event: keydown]`);
this.keys[e.key] = false;
});
//Message display field
this.canvas = document.getElementById("gameCanvas");
this.stage = new createjs.Stage(this.canvas);
this.messageField = new createjs.Text("Loading", "bold 24px Arial", "#FFFFFF");
this.messageField.maxWidth = 1000;
this.messageField.textAlign = "center";
this.messageField.textBaseline = "middle";
this.messageField.x = canvas.width / 2;
this.messageField.y = canvas.height / 2;
this.stage.addChild(this.messageField);
this.stage.update(); //update the stage to show text
console.log(this.messageField.text);
}
}
