我尝试编写包含玩家精灵和障碍物的简单游戏。我已经实现了一个带有重力的物理世界。我希望当玩家精灵落下时,它会靠近它落下的障碍物,但在重力作用下,精灵会以对角线方向而不是直线下降。
mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
...
public Player(PhysicsWorld world, final float pX, final float pY, final TiledTextureRegion pTextureRegion,
final VertexBufferObjectManager pVertexBufferObjectManager)
{
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
mPlayerDeff = PhysicsFactory.createFixtureDef(0, 0, 0);
mVertexBuffer = pVertexBufferObjectManager;
mBoardManager = BoardManager.getInstance();
mDirection = DIRECTION_RIGHT;
mWorld = world;
mBody = PhysicsFactory.createBoxBody(mWorld, this, BodyType.DynamicBody, mPlayerDeff);
mWorld.registerPhysicsConnector(new PhysicsConnector(this, mBody, true, false));
}