3

I am trying to develop a live wallpaper using andengine gles2 anchor center , with some physics.But when i add a physics object it was moving upwards.instead of moving downward due to gravity
what are the mistakes i am making please help me to sort out the issue

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));
Alexey
  • 714
  • 8
  • 21
Renjith K N
  • 2,613
  • 2
  • 31
  • 53
  • 1
    Multiply the gravity by -1? – David Feb 08 '13 at 19:05
  • No i dont do anything its the code above no multiplaction – Renjith K N Feb 08 '13 at 19:06
  • 1
    Perhaps change mPhysicsWorld into (SensorManager.GRAVITY_EARTH, 0). – David Feb 08 '13 at 19:07
  • tried its not helps its make the gravity to the right side – Renjith K N Feb 08 '13 at 19:13
  • Not exactly too knowledgeable about AndEngine/GLES2, but what's the parameters for `PhysicsConnector()`? – David Feb 08 '13 at 19:19
  • org.andengine.extension.physics.box2d.PhysicsConnector.PhysicsConnector(IEntity pEntity, Body pBody, boolean pUdatePosition, boolean pUpdateRotation) – Renjith K N Feb 08 '13 at 19:20
  • 1
    I can't seem to pinpoint the exact error. Hopefully this might bring some insight: https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/PhysicsExample.java – David Feb 08 '13 at 19:30
  • Thank you , Thank you David for your nice help hopes this will help me.. Thanks again – Renjith K N Feb 08 '13 at 19:33
  • Hello David , You are right just need to multiply by -1 solve the issue what we have to do is just add a minus sign to SensorManager.GRAVITY_EARTH like this mPhysicsWorld = new PhysicsWorld(new Vector2(0, -SensorManager.GRAVITY_EARTH), false); Please post you comment as an answer i willl mark it as the correct one – Renjith K N Feb 08 '13 at 20:11
  • Glad to see that it's no longer an issue. – David Feb 09 '13 at 03:38

2 Answers2

5

Just multiply SensorManager.GRAVITY_EARTH by -1.

David
  • 877
  • 1
  • 7
  • 18
0

Setting negative gravity did not respond properly to sensor data. By adding acceleration to the sensor data in the overridden method **onAccelerationChanged()**, could make the bject falling down with sensor flat.

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 in real gravity experience and you will get objects influenced by sensor data properly

Kulai
  • 630
  • 1
  • 6
  • 12