How to move a sprite automatically using a physicsHandler in Andengine?
Posted
by
shailenTJ
on Game Development
See other posts from Game Development
or by shailenTJ
Published on 2012-11-26T00:40:36Z
Indexed on
2012/11/26
5:24 UTC
Read the original article
Hit count: 615
I use a DigitalOnScreenControl (knob with a four-directional arrow control) to move the entity and the entity which is bound to a physicsHandler.
physicsHandler.setEntity(sprite);
sprite.registerUpdateHandler(physicsHandler);
From the DigitalOnScreenControl, I know which direction I want my sprite to move. Inside its overridden onControlChange function, I call a function animateSprite that checks which direction I chose. Based on the direction, I animate my sprite differently.
PROBLEM: I want to automatically move the sprite to a specific location on the scene, say at coordinates (207, 305). My sprite is at (100, 305, which means it has to move down by 107 pixels. How do I tell the physicsHandler to move the sprite down by 107 pixels? My animateSprite method will take care of animating the sprite's downward motion.
Thank you for your input!
© Game Development or respective owner