I suspect MathUtil::lerp() interpolates between a float to another, those are the first two parameters, so i guess it needs update in order to work isn"t?
I have used update correctly ( because i tested with CCLOG and works printing for ever) and put this:
If i change the third argument value to 0, then it prints 0 for ever in the log… So as you can see, no matter what range i put, it keeps printing the alpha value, is like args 0 and 1 are being skipped
That’s not quite how it works. This is the lerp implementation:
float MathUtil::lerp(float from, float to, float alpha)
{
return from * (1.0f - alpha) + to * alpha;
}
So, if you give it the same values, you’re going to get the exact same result.
As an example of how you would use it, say you’re moving an object along the X axis from X = 0 to X = 1000, and at a specified speed. You would implement it as follows:
ok, i guess i had missunderstood the way this function works…
i was thinking it like MoveTo (from specific point to another), but it work like MoveBy (get the current point, add and repeat untill target is required) isn´t?
once is finished, is there a way to stop update schedule to save performance?
thanks…
MoveTo and MoveBy are both actions, so they are not the same as MathUtil::lerp, which is just a function. The MoveTo and MoveBy actions are given parameters, and then that action is run an object, after which you have no control over them; you can only add or remove actions, and perhaps even pause them, but that is all.
They may be what you need. Have you even looked at the cpp-tests project? Demos of the majority of Cocos2d-x functionality is in there. If you haven’t, then run it, and learn from it.
Well, why use update at all? You can always schedule a function to be called every X period of time, and then unschedule it. Open up CCNode.h, and browse the code. It’ll be pretty obvious how to achieve this once you look at the code.
Hi. There is a very useful and underestimated action in cocos2d-x named ActionFloat.
This action performs like update with more control and you can pause and resume or stop it if you want. Take a look at it.
Actually this action somehow does the same thing as lerp function.