• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Re: design a simple a choose your own adventure text based game

Community Expert ,
Jan 01, 2023 Jan 01, 2023

Copy link to clipboard

Copied

this is the code needed to fix a previous post:

 

// in the fla:

if(!this.alreadyExecuted){

var g = new Game(exportRoot, this);

this.alreadyExecuted = true;

}

 

// comment out (most likely) problematic non-existent canvas

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: keyup]`);
this.keys[e.key] = false;
});

//Message display field

//this.canvas = document.getElementById("gameCanvas");
//console.log("canvas",this.stage);
//this.stage = new createjs.Stage(this.canvas);
this.messageField = new createjs.Text("Loading", "bold 24px Arial", "#00FFFF");
console.log("a",this.stage);
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);
}

}

Views

133

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 01, 2023 Jan 01, 2023

Copy link to clipboard

Copied

Sorry kglad - this code didnt work for me - I got a maximum call stack size exceeded in the createjs.min.js

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 01, 2023 Jan 01, 2023

Copy link to clipboard

Copied

are you executing new Game() once only?

 

if you think so, and if the code is on a timeline with more than one frame, explain 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 01, 2023 Jan 01, 2023

Copy link to clipboard

Copied

Sorry kglad there is no code on the timeline (and only one frame)  

I have searched the index.html and can only find reference to "game" in these places

<script src="game.js"></script> (to get the script)

var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation, game; (create the variable)

and 

function handleTick(event){
if (game === undefined) game = new Game(exportRoot, stage);
}

 

so I think that means there is only one game()?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 01, 2023 Jan 01, 2023

Copy link to clipboard

Copied

LATEST

Hey kglad do you mind if we move this part of our conversation over to my other thread about the messageField?

https://community.adobe.com/t5/animate-discussions/how-to-get-a-messagefield-working-from-a-class-fi...

I am confused enough without mixing up my questions in these threads - I am working on simple dynamic text boxes that are actually on the timeline here..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines