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

Android: Create List<Map<String, List<ObjectType>>

java android

Can someone help me solve my problem, how to create List&lt;Map&lt;Integer, List&lt;MyType&gt;&gt; in while cycle. I'm selecting data from database and I'd like to add objects, that accomplish sele...

How to discover the IP address of a Tomcat server on a network?

java tomcat networking

I have a Android application which consumes a webservice on a local network. There's a config screen where the user inform the server IP address, which is running Apache Tomcat.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.