I’m new to AndEngine programming. I want to move a sprite recreating a complex animation before the user can interact with it.
The initial movement of the sprite is not so linear and not so simple. I want to apply a complex Mathematical algorithm to the coordinates of the moving sprite.
How can I achieve this ? Which existing functions can I use in AndEngine ?
I’m new to AndEngine programming. I want to move a sprite recreating a complex
Share
Calculate your positions and store them into two
floatarrays. Each cell in the first array would be a X coordinate, and in the second array it would be a Y coordinate.Then, create a
Pathobject. Make sure it is AndEngine’sPathobject, not the regular Android SDK one (AndEngine one isorg.anddev.andengine.entity.modifier.PathModifier.Path).Create your
Paththis way:Where
coordinatesXandcoordinatesYare, of course,floatarrays.Now, all you have to do is create a
PathModifierwith yourPath:(
durationis afloatspecifying the time for the entity will move along the path. The smaller it is, the faster the entity moves. Experiment with different times to find out what works the best for you).Calling
setRemoveWhenFinishedwith atrueargument makes sure the path modifier will be unregistered when the path is completed.Then just register it to your sprite:
And you are done.