1
目的是限制一个box2d的物理体的移动在一定的轴 - 向水平或垂直移动,这里是主体定义:限制沿轴线在andEngine Box2D的身体的运动
Body ballBody;
Sprite ball;
ball = new AnimatedSprite(x_end, y_end-ballTextureRegion.getHeight(), this.ballTextureRegion, this.getVertexBufferObjectManager());
ballBody = PhysicsFactory.createCircleBody(this.mPhysicsWorld, ball, BodyType.DynamicBody, FIXTURE_DEF);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(ball, ballBody, true, true));
scene.registerUpdateHandler(this.mPhysicsWorld);
scene.attachChild(ball);
的在所有方向上球移动,通过使用andEngines IAccelerationListener,什么已经尝试限制沿x轴的主体,加速度计,以便它使只有垂直:
在主游戏循环,已经设置其线速度为0的x分量:
scene.registerUpdateHandler(new IUpdateHandler() {
public void reset() {
}
// main game loop
public void onUpdate(float pSecondsElapsed) {
ballBody.setLinearVelocity(0, ballBody.getLinearVelocity().y); // set x velocity as 0
}
});
但现在球也可以水平移动,其水平速度现在较小但不是全为0.如何限制其沿一个方向的移动?