无法用Box2D跳入Andengine

时间:2015-04-16 17:34:35

标签: andengine

我想在this tutorial之后让玩家跳跃,但我不能。请查看我的代码并帮我修复它。这是我的代码:

mPhysicsWorld = new PhysicsWorld(new Vector2(0, 

SensorManager.GRAVITY_EARTH),false);
sapo = new Sapo(100,100,mVertexBufferObjectManager,mCamera,mPhysicsWorld) {
   @Override
   public void onDie() {}
   };
attachChild(sapo);
sapo.jump();

public abstract class Sapo extends AnimatedSprite {
private Body mBody;

public Sapo(float pX, float pY, VertexBufferObjectManager vbo, Camera camera, PhysicsWorld physicsWorld)
{
    super(pX, pY, ResourceManager.getInstance().mSapoTiledTextureRegion,vbo);
    createPhysics(camera, physicsWorld);
}
private void createPhysics(final Camera camera, PhysicsWorld physicsWorld)
{        
    mBody = PhysicsFactory.createBoxBody(physicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(1f,1f,1f));
}

public abstract void onDie();
public void jump() {
    mBody.setLinearVelocity(new Vector2(mBody.getLinearVelocity().x,-100));
}

}

1 个答案:

答案 0 :(得分:0)

我发现了问题。我忘了注册物理处理程序,如下所示:

myScence.registerUpdateHandler(mPhysicsWorld);