Jump to content

Tween animations acting strange


ieaglev
 Share

Recommended Posts

I'm trying to add some movement to the enemies in my game, I have a function which includes the following:

 

    var enemyMovement = game.add.tween(this.enemies.children[0]); 
    enemyMovement.to({x: 230}, 1000, Phaser.Easing.Linear.None)
    .to({x: 50}, 1000, Phaser.Easing.Linear.None)
 
     start();
 
 
I have two problems:
 
1. I want the sprite to move at a constant speed, at the moment there is easing which I thought Phaser,Easing.Linear.None would handle.
 
2. The chaining will not work, the sprite will not move back and I have not idea why, I am getting no errors in my code. 
 
Thanks 
Link to comment
Share on other sites

Is that code copied directly from your source? If so, I'm seeing a couple formatting problems. First, when you create the tween, don't add the "to" as a separate function, use a dot separator, like so:

 

var enemyMovement = game.add.tween(this.enemies.children[0]).to({x: 230}, 1000, Phaser.Easing.Linear.None)

.to({x: 50}, 1000, Phaser.Easing.Linear.None)

.start();

 

Note that there are no semicolons until after start(). When I tried this code myself, it chained properly and did seem to move at a constant speed. (Also remember that if you want the chain to repeat, add a .loop() before the .start().) Anyway, hope that solves your problem!

Link to comment
Share on other sites

Is that code copied directly from your source? If so, I'm seeing a couple formatting problems. First, when you create the tween, don't add the "to" as a separate function, use a dot separator, like so:

 

var enemyMovement = game.add.tween(this.enemies.children[0]).to({x: 230}, 1000, Phaser.Easing.Linear.None)

.to({x: 50}, 1000, Phaser.Easing.Linear.None)

.start();

 

Note that there are no semicolons until after start(). When I tried this code myself, it chained properly and did seem to move at a constant speed. (Also remember that if you want the chain to repeat, add a .loop() before the .start().) Anyway, hope that solves your problem!

 

 

Thanks for the help, I used your code and it still wouldnt work. Then I moved it inside the create function, I had been calling it from the update function the whole time because that makes sense to me. So annoying that that was the problem the whole time!

 

Cheers

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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