【问题标题】:Why physics body automatically moves upwards in andengine gles2 anchor center live wallpaper为什么物理身体会在andengine gles2锚中心动态壁纸中自动向上移动
【发布时间】:2013-02-08 19:03:00
【问题描述】:

我正在尝试使用 andengine gles2 锚中心开发动态壁纸,并带有一些物理特性。但是当我添加一个物理对象时,它正在向上移动。而不是由于重力而向下移动
我犯了什么错误 请帮我解决问题

这是我的代码

FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f,
                0.5f);
mPhysicsWorld = new PhysicsWorld(new Vector2(0,
                        SensorManager.GRAVITY_EARTH), false);
final AnimatedSprite animatedSprite;
animatedSprite = new AnimatedSprite(500, 250,
                        this.mBoxFaceTextureRegion, this.getVertexBufferObjectManager());

body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, animatedSprite,
                        BodyType.DynamicBody, FIXTURE_DEF);

scene.attachChild(animatedSprite);
animatedSprite.animate(200);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
                        animatedSprite, body, true, true));

【问题讨论】:

标签: android andengine game-physics live-wallpaper


【解决方案1】:

只需将SensorManager.GRAVITY_EARTH 乘以 -1。

【讨论】:

    【解决方案2】:

    设置负重力没有正确响应传感器数据。通过在覆盖方法**onAccelerationChanged()** 中为传感器数据添加加速度,可以使物体在传感器平坦的情况下坠落。

    public void onAccelerationChanged(final AccelerationData pAccelerationData) { /* Add constant value for vertical gravity*/ final Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY() + 4.0); this.mPhysicsWorld.setGravity(gravity); Vector2Pool.recycle(gravity); }

    这将使您的物理世界处于真实的重力体验中,并且您将正确地获得受传感器数据影响的对象

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多