ieaglev Posted February 14, 2015 Share Posted February 14, 2015 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 More sharing options...
Triplanetary Posted February 15, 2015 Share Posted February 15, 2015 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 More sharing options...
ieaglev Posted February 15, 2015 Author Share Posted February 15, 2015 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 More sharing options...
Recommended Posts