Jump to content

Move a sprite along a path


Recommended Posts

Thanks for your answer administrator!


I'm currently working on a war map of the great war and  I whold like to have the troupes move and folow a elipse like path.


Look at the two first slides in this presentation from BBC



What is the best way to have sprites move like that



Link to comment
Share on other sites

  • 3 weeks later...

I couldn't seem to get the bezier interpolation working correctly in 2.0.4:

var tween = this.game.add.tween(obj).to({ x: 600 }, 2000)            .to({ y: 300 }, 1000, Phaser.Easing.Exponential.InOut)            .to({ x: 100 }, 2000, Phaser.Easing.Exponential.InOut)            .to({ y: 100 }, 1000, Phaser.Easing.Exponential.InOut)            .interpolation(Phaser.Math.bezierInterpolation)            .loop()            .start();

Many Thanks.

Link to comment
Share on other sites

After a bit of messing around and debugging through Phaser's code (this stuff isn't too well documented). It looks like the to construct needs changing to an array based format:


var tween = this.game.add.tween(obj.sprite).to({    x: [300, 800,  900, 0],    y: [600,  600, 200, 0],    angle: [360]}, 5000).interpolation(function(v, k){    return Phaser.Math.catmullRomInterpolation(v, k);});
Link to comment
Share on other sites

  • 3 months later...

This worked for me


var moveSprite = this.game.add.sprite(startX, startY, 'spritekey');
var tween = game.add.tween(moveSprite).to({
x: [startX, firstBezierPointX, secondBezierPointX, endX],
y: [startY, firstBezierPointy, secondBezierPointY, endY],
}, 1000,Phaser.Easing.Quadratic.Out, true).interpolation(function(v, k){
    return Phaser.Math.bezierInterpolation(v, k);
Link to comment
Share on other sites


  • Recently Browsing   0 members

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