What would be the best way to do this? I see the CCEaseSineInOut action but it doesn't look like that could be used to do this.
I need to move from one side of the screen to the other. The sprite should move in a sine-wave pattern across the screen.
I always like to have complete control over
CCNode
motion. I only useCCAction
s to do very basic things. While your case sounds simple enough to possibly do withCCAction
s, I will show you how to move aCCNode
according to any function over time. You can also change scale, color, opacity, rotation, and even anchor point with the same technique.For your specific problem, you could use Option 2 with
x(t) = k * t + c
, andy(t) = A * sin(w * t) + d
.Math note #1:
x(t)
andy(t)
are called position parameterizations.Vx(t)
andVy(t)
are velocity parameterizations.Math note #2: If you have studied calculus, it will be readily apparent that Option 2 prevents accumulation of positional errors over time (especially for low framerates). When possible, use Option 2. However, it is often easier to use Option 1 when accuracy is not a concern or when user input is actively changing the parameterizations.
There are many advantages to using
CCAction
s. They handle calling other functions at specific times for you. They are kept track of so that you can easily pause them and restart them, or count them.But when you really need to manage nodes generally, this is the way to do it. For complex or intricate formulas for position, for example, it is much easier to change the parameterizations than to figure out how to implement that parameterization in
CCAction
s.