Introduction to the Box2D physics extension
Physics-based games are one of the most popular types of games available for mobile devices. AndEngine allows the creation of physics-based games with the Box2D extension. With this extension, we can construct any type of physically realistic 2D environment from small, simple simulations to complex games. In this recipe, we will create an activity that demonstrates a simple setup for utilizing the Box2D physics engine extension. Furthermore, we will use this activity for the remaining recipes in this chapter.
Getting ready...
First, create a new activity class named PhysicsApplication
that extends BaseGameActivity
and implements IAccelerationListener
and IOnSceneTouchListener
.
How to do it...
Follow these steps to build our PhysicsApplication
activity class:
Create the following variables in the class:
public static int cameraWidth = 800; public static int cameraHeight = 480; public Scene mScene; public FixedStepPhysicsWorld mPhysicsWorld; ...