Phaser tween doesn't work inside of update function

316 views Asked by At

My tween doesn't start inside of the update() function. I don't really know how to realize it otherwise. Here's what I'm doing:

I'm working on turn-based combat. Inside of the update() function I have a switch(currentState) which switches states from START to PLAYERCHOICE to ANIMATIONS etc.

So inside of the ANIMATIONS part of it I have:

gameState.prototype = {

  preload: function() {  
    // preload game assets
  },

  create: function() {
    // create game objects
  }

  update: function() {
    PlayerAttack_Animation();
  },
}

function PlayerAttack_Animation() {

  player_dealt_dmg_alpha_tween = game.add.tween(player_dealt_dmg_txt).to( { alpha: 0 }, 1000, "Linear", true);
  player_dealt_dmg_y_tween = game.add.tween(player_dealt_dmg_txt).to( { y: (enemy.y-90) }, 1000, "Linear", true);

 }

It worked inside of a listener function when was called from create() function.

0

There are 0 answers