Phaser 3 Textadventure Example

Simple demo for phaser forum request

by ragesoft

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.2/phaser.min.js"></script>
<div id="main">

</div>

JavaScript

class Demo extends Phaser.Scene {
    constructor() {
        super({
            key: 'examples'
        })
    }
    
 preload() { 
 
 }
 
 
 create(){
 
 		this.add.text( 10,10, "Demo-scene for phaser forum request\nhttps://phaser.discourse.group/t/text-adventure-perfomance-problem/11394");
 		this.startBtn = this.add.text( 10, 60, "Click [here] Start" )
    	.on( "pointerdown", () => {
      	this.currentScenario = null;
      	this.letsGo();
      })
      .setInteractive();
      
    // simulation of JSON demo data
   	this.scenario = exampleJSON;
 
 		// the ui elements and there click-events
   	this.textElement = this.add.text(10, 280, "Place:");
   	this.textElement2 = this.add.text(10, 300, "office");
   	this.textElement3 = this.add.text(10, 340, "Use arrow keys to move.");
   	this.answer1 = this.add.text(10, 470, "")
   		.setStyle({ backgroundColor: '#111' })
      .on("pointerover", () => {
      	this.answer1.setStyle({ backgroundColor: '#aaa' })
      })
      .on("pointerout", () => {
      	this.answer1.setStyle({ backgroundColor: '#111' })
      })
      .on("pointerdown", (pointer) => {
      	// passing the action-key only, not the object
      	this.letsGo( "link1" );
    });  
   	this.answer2 = this.add.text(400, 470, "")
      .setStyle({ backgroundColor: '#111' })
      .on("pointerover", () => {
      	this.answer2.setStyle({ backgroundColor: '#aaa' })
      })
      .on("pointerout", () => {
      	this.answer2.setStyle({ backgroundColor: '#111' })
      })
      .on("pointerdown", (pointer) => {
      	this.letsGo( "link2" );
    	});
          

 }
 
 update(){
 
 }
 
 /**
  * a answer was clicked, go to the next scenario
  * @param {string} link - the current link to use for next scenario
 **/
 letsGo( link ) {
   console.log( "Lets go", link);
   // saving the current scenario or init it to first one
   if( !this.currentScenario  ) this.currentScenario = exampleJSON.one;
   if( link && this.currentScenario[ link ] &&...