Change Sprite Position onAccelerometerChanged

I am new in AndEngine. I use animatedSprite and Sprite Object. I want to move Sprite on the basis of accelerometer but i dont want to move animatedSprite also. I want physicsworld implementation

private void addBottomFace(final float pX, final float pY) {
    myBottomSticFace = new Sprite(pX, pY, myBottomStickTextureRegion);
    myBottomStickBody = PhysicsFactory.createBoxBody(this.myPhysicsWorld, myBottomSticFace, BodyType.DynamicBody, myFixtureDef);

    this.myScene.attachChild(myBottomSticFace);
    this.myPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(myBottomSticFace, myBottomStickBody, true, true));
}


@Override
public void onAccelerometerChanged(AccelerometerData pAccelerometerData) {
    final Vector2 gravity = Vector2Pool.obtain(pAccelerometerData.getX(), pAccelerometerData.getY());
    myBottomSticFace.setPosition(myBottomSticFace,getX() + pAccelerometerData.getX(), myBottomSticFace,getY());
    Vector2Pool.recycle(gravity);
}

With this code mBottomSticFace will move according to accelerometer but body does not moves.

Answers


You should create two different bodies and attach it to your sprites. The Body you want to be moved should be set as BodyType.DynamicBody, and the other one should be BodyType.StaticBody.

To see accelerometer and body examples, check this: http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/PhysicsExample.java


Need Your Help

how to create wrapper around std::bind

c++ c++11 function-pointers

I have a function object typedef std::function<bool(Event*)> Handler. A member function always gets assigned to this object. So, I am using std::bind to achieve that.

Mixing different categories results, ordered by score in MySQL

php mysql sql-order-by categories

In my PHP application, I have a mysql table of articles which has the following columns: