I create a Kinematic Body type plane sprite which will be moved continuously. So, I set a linear velocity to the body and that's why it moves continuously. But I have screen boundary roof, ground, left wall ,right wall .All of those are static body. When the plane moves it don't collide with the any boundary walls. After, studying on Box-2d manuals, I found a Kinematic Body never collides with other Kinematic Body & Static Body. So,either I set walls to Kinematic or Static Body still it doesn't collide with plane. When I set walls to Dynamic it falls down due to gravity. So, What should I do to set collisions between my plane and walls?
Here's the code:
private void initializePlaneAndBoundary() {
/*
* create wall boundary
*/
final Rectangle ground = new Rectangle(0, camera_Height - 2,
camera_Width, 2, vbom);
final Rectangle roof = new Rectangle(0, 0, camera_Width, 2, vbom);
final Rectangle left = new Rectangle(0, 0, 2, camera_Height, vbom);
final Rectangle right = new Rectangle(camera_Width - 2, 0, 2,
camera_Height, vbom);
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
0.5f, 0.5f);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, left,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, right,
BodyType.StaticBody, wallFixtureDef);
attachChild(ground);
attachChild(roof);
attachChild(left);
attachChild(right);
aPilot = new Pilot(222, 333, pilotTexures, vbom) {
@Override
protected void onManagedUpdate(float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
}
};
pilotBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, aPilot,
BodyType.KinematicBody, FIXTURE_DEF);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
aPilot, pilotBody, true, true));
pilotBody.setLinearVelocity(DEMO_VELOCITY_X, DEMO_VELOCITY_Y);
attachChild(aPilot);
}