Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Rotate a sprite around the center? — Gideros Forum

Rotate a sprite around the center?

StoffeStoffe Member
edited November 2011 in General questions
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?


  • atilimatilim 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

  • 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.

  • 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?
  • atilimatilim 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)
  • Yeah, no worries, was just curious for now. :)
Sign In or Register to comment.