JFish Posted September 26, 2014 Share Posted September 26, 2014 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 More sharing options...
Robske Posted September 26, 2014 Share Posted September 26, 2014 instead of reasigning the tween, just append the .to tweens, like this: tween = game,add.tween().to().to().to() etc Link to comment Share on other sites More sharing options...
lewster32 Posted September 26, 2014 Share Posted September 26, 2014 It's not well documented but you can tween in bezier arcs too: http://jsfiddle.net/lewster32/owjo33yu/ Petiiz 1 Link to comment Share on other sites More sharing options...
JFish Posted September 26, 2014 Author Share Posted September 26, 2014 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 More sharing options...
lewster32 Posted September 26, 2014 Share Posted September 26, 2014 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 More sharing options...
JFish Posted September 26, 2014 Author Share Posted September 26, 2014 Is the repeat function documented somewhere? I ask because I would like to understand the available parameters. Same for start() which I assume has a stop() - which would be valuable to me. Link to comment Share on other sites More sharing options...
lewster32 Posted September 26, 2014 Share Posted September 26, 2014 It's all here: http://docs.phaser.io/Phaser.Tween.html Link to comment Share on other sites More sharing options...
JFish Posted September 26, 2014 Author Share Posted September 26, 2014 Okay, sorry - I was looking at the easing section. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts