Rotate a sprite around the center? — Gideros Forum

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Rotate a sprite around the center?

Member
edited November 2011
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?
Tagged:

• Maintainer
I think you can use Bitmap's setAnchorPoint function. Its used to change the origin coordinates of the Bitmap (which is originally at the top-left corner)

For example,
 ```bitmap:setAnchorPoint(0, 0) --> top left corner bitmap:setAnchorPoint(1, 0) --> top right corner bitmap:setAnchorPoint(0.5, 0.5) --> center -- etc```

If your bitmap is 30x70 and if you want to place origin point at 15x55, then you should call:
 `bitmap:setAnchorPoint(15/30, 55/70)`
(Also, I know that currently setAnchorPoint function is not described at the documentation

I hope this solves your problem

• Member
Ah yes, precisely what I was looking for.

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!
• Maintainer
• Member
As a followup, are there any plans to add setAnchorPoint to Sprites/Shapes etc? Just needed it for a quick mockup I did with Shapes (a triangle) for quickest possible result, not that it's a big deal to add an image, but still, seems it would be natural to be able to rotate Shapes as well, at least?
• Maintainer
Hi Stoffe,

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:
 ```shape:moveTo(-50, -50) shape:lineTo(50, -50) shape:lineTo(50, 50) shape:lineTo(-50, 50)```
• Member
Yeah, no worries, was just curious for now.
• Maintainer