Hi!
I’m new in phaser and my english is bad. I will try to explain my problem:
I made a RPG text adventure. Move around in an office. A click on a character starts a dialog with two answer options (text objects). I stored the dialogs in a json file. The dialogs and the answers work fine. But if you start dialogs several times the browser lags (cpu: 100) and crashes. Every dialog replace an existing text object.
/// code in create()
this.textElement = this.add.text(10, 780, "Place:");
this.textElement2 = this.add.text(10, 800, "office");
this.textElement3 = this.add.text(10, 840, "Use arrow keys to move.");
this.answer1 = this.add.text(10, 870, "").setStyle({ backgroundColor: '#111' });
this.answer2 = this.add.text(400, 870, "").setStyle({ backgroundColor: '#111' });
/// click on a character (it is in another scene):
textGame.events.on("textSecurity", function () {
this.letsGo(this.scenario.one);
this.linkGo(this.linkAction.one);
}, this);
/// the json-File:
this.scenario = this.cache.json.get("scenario");
this.letsGo = function(s){
this.textElement.text = "Security:";
this.textElement2.text = s.text;
this.textElement3.text = "What's your answer";
this.answer1.text = s.ant1;
this.answer1.setInteractive();
this.answer2.text = s.ant2;
this.antswer2.setInteractive();
};
///code in update()
this.linkAction = {
one: {
link1: this.next2,
link2: this.next3,
next1: this.linkNext2,
next2: this.linkNext3
},
two: {
link1: this.next4,
link2: this.next3,
next1: this.linkNext4,
next2: this.linkNext3
},
three: {
link1: this.next4,
link2: this.next5,
next1: this.linkNext4,
next2: this.linkNext5
}
/// and so on
};
this.linkGo = function(l){
this.answer1.on("pointerdown", function(pointer){
this.letsGo(l.link1);
this.linkGo(l.next1);
}, this);
this.answer2.on("pointerdown", function(pointer){
this.letsGo(l.link2);
this.linkGo(l.next2);
}, this);
};
this.next1 = this.scenario.one;
this.next2 = this.scenario.two;
this.next3 = this.scenario.three;
this.next4 = this.scenario.four;
this.next5 = this.scenario.five;
///...
this.linkNext1 = this.linkAction.one;
this.linkNext2 = this.linkAction.two;
this.linkNext3 = this.linkAction.three;
this.linkNext4 = this.linkAction.four;
this.linkNext5 = this.linkAction.five;
/// example text in the json-file (shortened):
"one": {
"text": "some text",
"ant1": "some text,
"ant2": "some text",
"link1": "this.next2",
"link2": "this.next3"
},
"two": {
"text": "some text",
"ant1": "some text",
"ant2": "some text,
"link1": "this.next4",
"link2": "this.next3"
},
Can anyone help? Thanks alot!