I am tracking the path of a ball (CircleShape) that rolls around an irregular landscape. As long as I had a ball-shaped sprite and just copied position and rotation it worked just fine, but now I want to show a different object that is not at all ball shaped, at the same time as I want to set a manual rotation of this displayed sprite.
I think the problem is that the rotation is not around the center, but rather around a corner, and maybe it is that way in the CircleShape as well? I can't really find this information.
I've tried to rotate with matrix translations but I'm still doing something wrong.
Some more facts:
The ball rolling around is 15px in radius, 30px in diameter. The object I want to display instead is 30x70px and the place to rotate around is at the coordinates 15x55px, that is, at the center of a circle inscribed at the bottom of that rectangle. I've also tried making the sprite bigger, to 110x110px with transparency to get the center of the sprite to match, but obviously the rotation is not around the center.
Is there a way to do this computation, correctly using the positional data of the CircleShape and a manual rotation together?
Comments
For example,
If your bitmap is 30x70 and if you want to place origin point at 15x55, then you should call:
I hope this solves your problem
Still seems as if CircleShape is not centered either, since if it starts to rotate it throws stuff off, right now have turned of friction and rotation so it seems to work so far.
Thanks!
I'm planning to add setAnchorPoint to Shape and Textfield but unfortunately not to Sprite because setAnchorPoint doesn't have any effect on position of children. (I'm still thinking about what I can add to Sprite similar to setAnchorPoint)
I'm sure you already know but you can create a centered square shape by: