Why does the physical body automatically move up and into live wallpaper with gles2 snapping

I am trying to design a live wallpaper with andengine gles2 anchor center with some physics. But when I add a physics object, it moved up. Instead of moving downward due to gravity
what mistakes am I making please help me figure out the problem.

Here is my code

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

      

+3


source to share


2 answers


Just multiply SensorManager.GRAVITY_EARTH

by -1.



+5


source


The negative gravity setting did not respond properly to the sensor data. By adding acceleration to the sensor data in an overridden method **onAccelerationChanged()**

, you can make the tray fall down using the sensor.

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



This will make your phy world a real gravitational experience and you will correctly get objects influenced by sensor data.

0


source







All Articles