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 68px Arial", "#OOOOOO");
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.root.messageField);
this.stage.update(e); //update the stage to show text
console.log(this.messageField.text);
}
}
I have this code on my class file game.js - the keys are being logged, the messageField can be logged in the console, but there is no text in the project when it is run. No errors are being thrown by this code. Any pointers greatly appreciated :) thank you sub
I have been working on how to create working Javascript to run from a game.js file to control an adobe animate cc HTML5 Canvas.
I have been asking various questions here and working out how to make it go https://community.adobe.com/t5/animate-discussions/changing-code-to-get-it-to-work-from-a-class/td-p/13454073#M360897 and here for the current query https://community.adobe.com/t5/animate-discussions/how-to-get-a-messagefield-working-from-a-class-file/td-p/13455867
I did notice that the text is set to white and thought if I changed it to black I would see the text (I was very happy with myself for a moment)- but you still can't see the text in the final project