- Posts: 12
- Thank you received: 4
Sprite rotation
3 weeks 9 hours ago #54
by rosogon
Sprite rotation was created by rosogon
Hi,
Is there any way to rotate a sprite, either by code or using the sprite editor?
Thanks
Is there any way to rotate a sprite, either by code or using the sprite editor?
Thanks
Please Log in or Create an account to join the conversation.
3 weeks 4 hours ago #55
by Franck
Replied by Franck on topic Sprite rotation
There's no rotation function in the sprite editor (or the image editor) a the moment. But I'll look into it when I've got some time for a future release.
It is obviously impractical to try doing it in real time, but precomputing in code shouldn't be that difficult.
I would recommend doing it all in bitmap to benefit from the built-in functions and then convert to sprites at the end.
There are two approaches:
The second should be quite fast, as it was intended for real-time hardware implementation, but is more complex to implement.
If it's just to precompute and save as a file, I'd go with the first approach. May I ask what is your use case?
It is obviously impractical to try doing it in real time, but precomputing in code shouldn't be that difficult.
I would recommend doing it all in bitmap to benefit from the built-in functions and then convert to sprites at the end.
There are two approaches:
- Using a rotation matrix to transform each pixel, something similar to this: www.lexaloffle.com/bbs/?tid=38548
- Using the shear method, used by many 16-bits arcade: games: www.ocf.berkeley.edu/~fricke/projects/is...ion_by_shearing.html
The second should be quite fast, as it was intended for real-time hardware implementation, but is more complex to implement.
If it's just to precompute and save as a file, I'd go with the first approach. May I ask what is your use case?
Please Log in or Create an account to join the conversation.
3 weeks 3 hours ago #56
by rosogon
Replied by rosogon on topic Sprite rotation
Hi Franck,
Sorry, I should have been more specific. My use case is much simpler, for the moment. I am moving a ship ( I got the sprite from multi.spr) in 4 directions and I want it to have the right orientation. I use sprFlip for up/down but for left/right I need to rotate it 90º.
Since there is no support yet, I will try to rotate it in memory on start up time. Thanks for the pointers: they will be useful if I ever need something more complicated.
Best,
rosogon
Sorry, I should have been more specific. My use case is much simpler, for the moment. I am moving a ship ( I got the sprite from multi.spr) in 4 directions and I want it to have the right orientation. I use sprFlip for up/down but for left/right I need to rotate it 90º.
Since there is no support yet, I will try to rotate it in memory on start up time. Thanks for the pointers: they will be useful if I ever need something more complicated.
Best,
rosogon
Please Log in or Create an account to join the conversation.
2 weeks 6 days ago #57
by rosogon
Replied by rosogon on topic Sprite rotation
I realized that given a sprite is 24x21pixels, the rotated ship would not fit. So I dedicated 10 minutes in the editor to rotate it myself, removing two lines.
The following user(s) said Thank You: Franck
Please Log in or Create an account to join the conversation.
2 weeks 6 days ago - 2 weeks 5 days ago #58
by Franck
Replied by Franck on topic Sprite rotation
Couldn't resist. I wrote a small utility to precompute sprite rotations. It computes rotations from 0 to 90 degrees, the rest is handled by using the hardware flipping. Example usage included. It will also be added to the upcoming 0.7.5 update. (edit: added screenshot)
This attachment is hidden for guests.
Please log in or register to see it.
Please log in or register to see it.
Last edit: 2 weeks 5 days ago by Franck.
The following user(s) said Thank You: rosogon
Please Log in or Create an account to join the conversation.
2 weeks 5 days ago #59
by rosogon
Replied by rosogon on topic Sprite rotation
It works like a charm!
I think I found a nasty bug. I will create a new post for that.
I think I found a nasty bug. I will create a new post for that.
Please Log in or Create an account to join the conversation.
Time to create page: 0.168 seconds