Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / How to rotate sprite with pivot at the center of sprite?

Author
Message
floccipocci
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location:
Posted: 9th Sep 2003 11:06
I noticed that using the ROTATE SPRITE command only seems to rotate the sprite using the top-left corner of the sprite image (or 0,0) as the pivot.

Is there any way on how to rotate a sprite about it's center?

I was thinking of using a method of rotating the sprite and then calculating the offset to move the sprite back. So that the center of the rotated sprite is moved back to center of the sprite before it was rotated, but I found this to be a little bit more complicated for such a simple task.

Thank you.
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 9th Sep 2003 11:08 Edited at: 9th Sep 2003 11:09
use the offset sprite command, just use
offset sprite spr,sprite width(spr)/2,sprite height(spr)/2
where spr is the sprinte number you want to offset


floccipocci
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location:
Posted: 9th Sep 2003 11:23
Hm, it does not seem to work. Now it seems that the rotation point is at the middle of the right side of the sprite. I still have to figure out how this happens.

Actually, what I'm trying to do now is just make a small little "airplane" fly around, using left and right arrows to rotate, and forward to make it go forward.

So if the plane is stationary, the left and right keys would make it spin on the spot.

Right now, the above method seems to give the plane a bigger right-turn flying arc, than a left-turn flying arc. What I'm talking about here is when I press the forward key with either a left or right arrow key.

Thank you anyway. I see what I can do.
floccipocci
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location:
Posted: 9th Sep 2003 11:29
Anyway, here's the code to handle the movement.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Sep 2003 12:03
... and here's the fixed version

You only need to use the offset sprite command whenever you change the image to keep it centred, and only if the image is a different size from the previous one.
floccipocci
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location:
Posted: 9th Sep 2003 17:06
It works now. Thanks a lot. Finally I understand a bit of the sprite properties regarding offsetting the position of the sprite.

I also noticed that the image in my bitmap is not really drawn at the center but was actually way off the center, so it was my mistake that made it seem that the sprite is not being rotated at the exact center.

Login to post a reply

Server time is: 2024-04-20 16:18:05
Your offset time is: 2024-04-20 16:18:05