Reputation: 181
I am trying to rotate an object from one point which is changing while rotating.
When I call to setRotationCenter(float,float) the IMAGE of the object moves to some arbitrary point. This only happens with rotated objects, I mean, if I call setRotationCenter in an object with rotation=0, everything works well.
My Class extends Sprite. I am not overriding setRotationCenter. My AndEngine version has not been updated for long.
I post a log of what I am doing and numbers I got. All should be ok looking at them, but I am actually seing my object in the screen moving along vector v(1,1) (notice that is the increment of rotation center)
log item touch event previous rotation 30.0
log item touch event previous rotation center 150.0: 150.0
log item touch event previous position 100.0: 150.0
log item touch event CALL TO setRotationCenter(151.0,151.0);
log item touch event current rotation 30.0
log item touch event current rotation center 151.0: 151.0
log item touch event current position 100.0: 150.0
log item touch event previous rotation 30.0
log item touch event previous rotation center 151.0: 151.0
log item touch event previous position 100.0: 150.0
log item touch event CALL TO setRotationCenter(152.0,152.0);
log item touch event current rotation 30.0
log item touch event current rotation center 152.0: 152.0
log item touch event current position 100.0: 150.0
Upvotes: 1
Views: 1571
Reputation: 2867
This is expected behaviour. setRotationCenter
changes the point that the object is rotated around. Initially your object is rotated 30 degrees around 150,150, but then you are telling it to be rotated 30 degrees around 151,151. The object's angle of rotation will continue to look exactly the same, but because it is now rotated around a different point it will appear to have moved.
If you start with an object with zero rotation, both of the following snippets of code will make it end up in the same position:
object.setRotationCenter(150, 150);
object.setRotation(30);
object.setRotationCenter(151, 151);
and:
object.setRotationCenter(151, 151);
object.setRotation(30);
Note that if you're using the GLES2-AnchorCenter version of AndEngine, then the arguments to setRotationCenter should normally be in the range 0.0 to 1.0, because they are a proportion of the width/height of the object. I.e. setRotationCenter(0.5f, 0.5f)
would make the object rotate around its center. But if you're using the GLES2 version, then what you've got is probably correct.
Upvotes: 7