Reputation: 11
I move a body in andengine and regained its position as in X, Y
and use:
Get Position:
body.getPosition().x;
AnimatedSprite.getX();
Set Position:
Sprite.setPosition(x,y);
but none served me.
Upvotes: 0
Views: 2484
Reputation: 11
you can do this
yourBody.setTransform(new Vector2(x/32,y/32), 0);
this question is the same as how to move body of sprite using andEngine?
Upvotes: 0
Reputation: 200
You should do it in registerUpdateHandler in method onUpdate.
Example:
body.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() {
}
@Override
public void onUpdate(float pSecondsElapsed) {
body.getPosition();
body.setPosition();
}
});
Upvotes: 0
Reputation: 6895
If I understand correctly what your problem is, the method you are looking for is Body.setTransform(float x, float y, float angle)
. Remember that the Body coordinates are in meters, so you have to divide the pixel value by your PIXEL_TO_METER_RATIO
(usually 32).
Upvotes: 3