Moving object in a Sine curve?

Hi all,

any ideas how to make a move object with the “transition.to” using easing in a sine curve from right to left screen?
I have tried more easing effects but with no result.
Any comment will be appreciated.

Thanks in advance

Marco
[import]uid: 7518 topic_id: 2054 reply_id: 302054[/import]

I’ve not tried having two transitions on an object, but if its possible, could you have one changing the x value and another changing the y value. Each time the y changer fires its onComplete event you would just create another transition which changes the y value in the opposite direction?

If two transitions are not possible on an object, at the same time, then just have a loop (maintained by a timer or enterFrame event?) to change the x value.

Am I on the right lines with what you’re attempting? [import]uid: 8271 topic_id: 2054 reply_id: 6041[/import]

Thanks horacebury.
I have tried with two transitions like this:

transition.to(Enemy2, {time=5000, x=x, y=y-100, onComplete=RemoveObj , transition = easingx.easeOutElastic} )  
transition.to(Enemy2, {time=5000, x=x-100, y=y, onComplete=RemoveObj , transition = easingx.easeOutElastic} )  

but only the last line will be executed.
I think that the only way is a routine controlled by “enterframe”.

Thanks
Marco
[import]uid: 7518 topic_id: 2054 reply_id: 6059[/import]

hi Marco,

the two transitions are in conflict that’s why only one is executed
transition.to is good only for linear transitions, i.e, move from point (x1,y1) to (x2,y2) in a straight line

you must have an enterframe listener and with that you will control both the x and y values.
for a full sine curve the formula is y=y0+a*sin(2?x/L), where ?=math.pi, y0 is the initial y value of the object, a is the amplitude (how far along the y axis you want the object to oscillate) and L is the distance along the x-axis that you want the object to move (stage width minus or plus the width of the object), and x is the x coordinate.

divide the width of the screen by n (number of steps), that will be your dx
in the enterframe listener make x increase by dx at each step, and y according to the formula above (y0, a, ?, and L are constants, only x and y change) [import]uid: 6459 topic_id: 2054 reply_id: 6062[/import]

I’ve just tried this:

local d = display.newImage( “crate.png” )
d.x = 100
d.y = 100

transition.to( d, {x=500, time=5000})
transition.to( d, {y=500, time=5000})

Note that each transition is only modifying one property of the object. This stops the transitions from being in conflict. This is what I meant in my earlier post. Have you tried this? [import]uid: 8271 topic_id: 2054 reply_id: 6070[/import]

Hi tetu,
thanks for your idea!
Below the correct code for moving an object in a sine curve:

local y0=Enemy2.y  
local EnemySpeed = 15  
local Amplitude = 60  

…and put this an enterframe listener function

local y=y0+math.sin(Enemy2.x/EnemySpeed)\*Amplitude  
Enemy2.x = Enemy2.x +1  
Enemy2.y = y  

Thanks also to horacebury!

[import]uid: 7518 topic_id: 2054 reply_id: 6224[/import]

That code above by GuGuGames works great for moving the object in a sine curve. I’d like to adjust it, though, so that upon a touch event, my player moves down the screen (y axis) and then when the touch is released, the player jumps upwards on the sine wave, which is then proportionally larger based on the distance the player previously moved down the screen. Any ideas?

This is basically the functionality in the sine-wave game Mighty Fin. http://launchingpadgames.com/games/mighty-fin/

http://developer.anscamobile.com/forum/2012/03/17/help-mighty-fin-style-game-physics [import]uid: 135391 topic_id: 2054 reply_id: 95831[/import]

Not tested, I *GOOGLED* it.

http://sree.cc/corona-sdk/create-an-animated-sine-wave-in-corona [import]uid: 79135 topic_id: 2054 reply_id: 95852[/import]