Rotating sprite around its center

Hello every one!

I have a simple tack in front of me. I need to rotate sprite around its center, not top/left corner. I was experimenting and search for suggestions, but best i could get is sprite rotating properly, but jumping around canvas. I was trying to ajast coordinates right after rotation, but didnt manage it.
Can anyone point me in the right direction or simply tell me how to do it?

Set origin to 0.5,0.5

1 Like

Thanks!
I am relativly new to mit app inventor, so could you please, explain little bit more? what is it and what it does?

OriginX
Horizontal unit coordinate of the origin with respect to left edge. Permitted values in [0, 1]. A value of 0.0 means the origin lies on the left edge, 0.5 means the origin lies in the middle and 1.0 means the origin is on the right edge.
OriginY
Vertical unit coordinate of the origin with respect to top edge. Permitted values in [0, 1]. A value of 0.0 means the origin lies on the top edge, 0.5 means the origin lies in the middle and 1.0 means the origin is on the bottom edge.

https://ai2.appinventor.mit.edu/reference/components/animation.html#ImageSprite

1 Like

Oh, My Got!

This is so simple. Thank you so much, guys, for your help!!!!

  1. Add a canvas
  2. Add an imageSprite to your canvas
  3. Upload an image file for your imageSprite
  4. Set the image file to your imageSprite
  5. Set the x,y of the imageSprite to the centre coordinates of your canvas (e.g. x=150,y=150 for a canvas 300x300)
  6. Scroll down the imageSprite properties on the right to find the Mark Origin section
  7. Set OriginX to 0.5
  8. Set OriginY to 0.5
  9. Your imageSprite should now be centred on its x,y position

AIA on rotating the sprite coming in a minute or two

Thank you, TIMAI2

Just tryed and it works. Now, have to figure out how to move my sprite back to center of canvas. After ajusting Origins, my sprite jamped to top right corner...

You need to do things in the order I set out, and sorry, I omitted the step of setting the x,y of the sprite, previous post now updated.

You may have to delete your existing sprite and start again.

AIA

rotateImageSpriteAroundCentre.aia (3.8 KB)

1 Like

Great sample an explanation!
All nice and clear now.

Thank you a lot!!!!

1 Like

Alternative using heading

rotateImageSpriteAroundCentreV2.aia (3.1 KB)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.