Android AndEngine Physics Box2D-即使没有任何传感器变化,动画精灵图像也会移动

Android AndEngine Physics Box2D-即使没有任何传感器变化,动画精灵图像也会移动,android,box2d,andengine,Android,Box2d,Andengine,我有一个动画精灵作为播放器,我使用IAccelerometerListener来回移动到播放器。 问题是,即使设备放在桌子上不动,我的播放器也会向上或向右移动 谁能指出我错过了什么。下面是我的代码 public Scene onLoadScene() { ..... physicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false); /** for POTRAIT */ fi

我有一个动画精灵作为播放器,我使用IAccelerometerListener来回移动到播放器。 问题是,即使设备放在桌子上不动,我的播放器也会向上或向右移动

谁能指出我错过了什么。下面是我的代码

public Scene onLoadScene() {
.....
physicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);


    /** for POTRAIT */
    final Display display = getWindowManager().getDefaultDisplay();
    int cameraWidth = display.getWidth();
    int cameraHeight = display.getHeight();
    final Shape ground = new Rectangle(0,cameraHeight, CAMERA_WIDTH,0);
    final Shape roof = new Rectangle(0,cameraHeight - (player.getHeight() * 2)  , CAMERA_WIDTH, player.getHeight() / 2);
    final Shape left = new Rectangle(0,0, 2,cameraHeight);
    final Shape right = new Rectangle(cameraWidth , 0, 2, cameraHeight);

    final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0, 1);
    PhysicsFactory.createBoxBody(this.physicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.physicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.physicsWorld, left, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.physicsWorld, right, BodyType.StaticBody, wallFixtureDef);

    this.mMainScene.attachChild(ground);
    this.mMainScene.attachChild(roof);
    this.mMainScene.attachChild(left);
    this.mMainScene.attachChild(right);

    mMainScene.registerUpdateHandler(physicsWorld);
    final Body grd = PhysicsFactory.createBoxBody(physicsWorld, player, BodyType.DynamicBody, FIXTURE_DEF);

    this.mMainScene.attachChild(player);
    physicsWorld.registerPhysicsConnector(new PhysicsConnector(player,grd, true, true));


}

如果x和y值大于该阈值,则可以设置阈值并签入AccelerationChanged方法,然后更新精灵,否则忽略该更新步骤。 比如:

@Override
    public void onAccelerationChanged(AccelerationData pAccelerationData) {
        // TODO Auto-generated method stub
        if(pAccelerationData.getX() > THRESHOLD_X || pAccelerationData.getY() > THRESHOLD_Y) {
          // update your sprite now...

        }
    }