andengine android中的引力问题

时间:2014-08-29 12:23:42

标签: android andengine uigravitybehavior

我试图编写包含玩家精灵和障碍的简单游戏。 我用重力实现了物理世界。我希望当玩家精灵掉落时,它会靠近它掉落的障碍物,但是在重力作用下,精灵会落在对角线而不是直线向下。

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));

}

current state and wanted state

1 个答案:

答案 0 :(得分:0)

您可以尝试将质量数据设置为您的身体:

MassData mass = new MassData();
mass.mass = 10; // in kilograms

mBody.setMassData(mass);