Sign in to follow this  
ieaglev

Tween animations acting strange

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 

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.