Jump to content

Move in a circle or pattern


JFish
 Share

Recommended Posts

Super newb here again with a pretty basic question.  i managed to spawn a group and thanks to a mod post I figured out that easing does not play well with physics so I set the body.move to false and case ease from one spot to another.  I then tried to create a zig-zag pattern with easing in chunks:

tween = game.add.tween(enemies.getAt(1)).to( { x:enemies.getAt(1).x-20, y:enemies.getAt(1).y+20}, 2400, Phaser.Easing.Circular.In, true);tween = game.add.tween(enemies.getAt(1)).to( { x:enemies.getAt(1).x-20, y:enemies.getAt(1).y-20}, 2400, Phaser.Easing.Circular.In, true);tween = game.add.tween(enemies.getAt(1)).to( { x:enemies.getAt(1).x-20, y:enemies.getAt(1).y+20}, 2400, Phaser.Easing.Circular.In, true);tween = game.add.tween(enemies.getAt(1)).to( { x:enemies.getAt(1).x-20, y:enemies.getAt(1).y-20}, 2400, Phaser.Easing.Circular.In, true);

However, it does not execute after the first one.  I am wondering if there is an easier way to create a movement pattern for an arc or a circle (or an equally/more difficult one that works).  Any help would be appreciated.

Link to comment
Share on other sites

Thanks for the responses.  Quick question - are tweens the best way to accomplish this?  Ideally I would like to adjust the position of the sprite with x,y but once then I need some sort of conditional logic with a timer to make sure it does not get called every second in the loop.  Tweens seem to have the advantage of moving to a targeted spot and then stopping.  What is best practice?

 

Also, @lewster32 - great function - thank you very much for demonstrating it.  Is the last part also somewhat undocumented? I briefly looked at tweens and did not see it:

 tween.repeat(Infinity); tween.start();
Link to comment
Share on other sites

The use of Infinity for repeat is both a habit I've gotten into, and it actually makes the bezier tweens loop as expected - if you try the normal loop method, it treats the first step of the tween as a bezier point, so it never returns to the start position. I guess this is technically correct, but unexpected and usually undesirable. If however you mean the separate methods, this is just a long-hand way of setting off a tween as opposed to the usual short-hand way:

// Autostart a tween to move the sprite to 10, 10 over 1 second with Quadratic easing, with no delay, and loop it infinitely back and forth with yoyoinggame.add.tween(sprite).to({x: 10, y: 10}, 1000, Phaser.Easing.Quadratic.InOut, true, 0, Infinity, true);

As far as I know, you cannot use this syntax alone to add interpolation to a tween, as there's no parameter for interpolation.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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