I just started using AndEngine, and it’s tough to find good tutorials / documentation.
I am making a 2D side-scroller game, where platforms and walls are generated randomly.
The user can control the player’s movement (jumping, walking forward).
I have a few general questions:
How do I get a parallax background to scroll only when the player moves?
Should I set the physics world gravity to nothing, and add the force of gravity to each individual object that actually needs it? I don’t want gravity to affect floating platforms/walls.
How do I animate a player when it moves (animated walking)?
What is the best way to go about collision detection (player/enemy, player/wall/platform, etc.)?
Sorry, that may have been a lot to ask at once.
Any help is appreciated!
I have never used parallax backgrounds, but I guess that the background moves as the camera moves. If the player doesn’t move, the camera shouldn’t move so the background won’t move either.
No, use the gravity. When creating bodies that should be unaffected by forces (Thus immovable) you use the
BodyType.StaticBodyoption. Static bodies can not be moved (Only by code).Take a look in the AnimatedSpritesExample. Basically, to animate a sprite it must be instantiated form the
AnimatedSpriteclass and you need to supply it with aTiledTextureRegion(Contains several regions, each with a different image). Then, by calling theanimatemethod ofAnimatedSpriteclass you can start the animation.If you plan on using Box2D, you can implement a callback called
ContactListenerwhich will be called when bodies collide in yourPhysicsWorld.If you don’t plan on using Box2D, you can use AndEngine’s methods for collision detection.
Here is an example.