Jump to content

Unsure if I'm using update() right and potential scoping issues


lemmikens
 Share

Recommended Posts

Hi there, I want to return a variable from inside the "Create()" function and use it inside of the "Update()" function. This is kind of a two part question. First of all, how would I use the variable updateStart below in the Phaser "Update()" function? It seems that even when I make it global, that startUpdate never gets set when it's inside of a function. Secondly, my game has to do with player movement after the create function after that updateStart function is set. Is the right way to go about it? Any suggestions would be greatly appreciated. This is only part of my "create()" function, by the way. I truncated a lot of it for readability. 

Thanks!

function create(){

  this.input.on('drop', function (pointer, gameObject, dropZone) {

    gameObject.x = dropZone.x;
    gameObject.y = dropZone.y-65;

    setXY = [dropZone.x, dropZone.y];
    console.log("x = " + dropZone.x + ", y = " + dropZone.y);
    dropZone.clearTint();
    //makes it so 'mans' can still receive input after drop
    gameObject.input.enabled = true;
    clickButton
      .setInteractive()
      .on('pointerdown', function(pointer){
        locked_in = this.add.image(400,400,'locked_in');


        startSpots.clear(true, true);
        gameObject.input.enabled = false;

        tween = this.tweens.add({

          targets: locked_in,
          x: 400,               // '+=100'
          y: 300,               // '+=100'
          ease: 'Elastic.easeInOut',       // 'Cubic', 'Elastic', 'Bounce', 'Back'
          duration: 2500,
          repeat: 0,            // -1: infinity
          yoyo: false,
          alpha: {
            getStart: () => 1.0,
            getEnd: () => 0
          },
          onComplete: () => {
          }

        });

        clickButton.destroy();
        clickButton.disableInteractive();
        updateStart =  true;
      }.bind(this));
  }.bind(this));
}

function update (updateStart) {
  console.log('update');
  if (updateStart == true) {
    console.log('bleh');
  }

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...