Want to rotate sprites around any pivot point of your own choosing? Don't want to import individual sprites, then set each one's center point?

With this, you don't have to. This demo showcases rotating sprites, with an included pixel perfect camera to make the rotating sprites not seem "messed up" when they rotate. The sprites are all coming from the same .png sprite asset file.

Instead of importing each individual sprite, and then setting each sprite's center point around which to rotate (in the sprite assets themselves), this uses spritesheets.

The benefit of a spritesheet is improved asset management. A lot of sprites can be part of a single image, meaning you only have to import 1 asset instead of a whole lot. Using code like "draw_sprite_part" or "draw_sprite_general", you can then select what part of a spritesheet you want to draw. But by doing this, the drawn sprite's origin point is placed in the top left corner of the drawn sprite! When you choose to rotate them (with the "rot" argument in draw_sprite_general for example), they will rotate only around that top left corner.

This solves that problem. Using trigonometry, this demo/asset makes it possible to draw sprites from a spritesheet, and then to select a new pivot point for them. The basics of how it works are explained in a separate image file.

All you, as a user of this package, need to do is adjust only 4 numbers in the object's CREATE event. That's it. Just 4 numbers cause the whole thing to rotate exactly like you want. 2 Numbers for the pivot point, and 2 numbers for the rotation behavior. And all this with a minimum amount of easy to read code required.

Included in this package is:

  • 9 objects, each representing a different rectangle dimension (imagine these being any sprite canvas you select on a spritesheet).

  • 3 sprites: the important showcase "SPR_SpriteResource" spritesheet, an unimportant SPR_Object, and a "sprite" which is a picture of how the basic math works. I included the explanation to how the trigonometry works if you choose the sprite's center as the new pivot point. Including offsets from the center is derived from this logic and is used in the object's code.

  • A pixel perfect camera, one that doesn't make the sprites appear "messed up" when they rotate.

  • An object that draws the demo text to the screen.

  • A room to showcase what's happening when running the project.

Just open a rectangle object, set its values, press "Run", and enjoy your rotating sprites from any pivot point you like, from any spritesheet you desire. Just keep in mind that this math is useful for "pleasing to the eyes rotations". There is still a small offset in the way it works. This causes a microscopic offset at "normal speed rotations". Don't increase or decrease your angle increments by too much and it should be fine. Anything between -7 and +7 still looks very good, and at those specific values the rotation is already quite fast. When you increase or decrease to very large amounts, math offset and the trigonometry causes the sprites to spiral "away from center orbit" so to speak, and rotate at a new radius at epilepsy-inducing patterns. By then they are flashing around so fast it's hard to imagine such a thing could ever be useful. So just try to keep the rotation pleasing to the eyes. Also, at certain large increments like 90, 180 or 270, you can create some kind of resonance structure. Pretty weird to see, but at those rotating speeds I can't imagine it to be useful, so keep it between low values. It's better to actually see the sprite rotate, in a way our eyes can still catch.

The lines of code per object needed are very few, I tried to make the math as compact as possible. Just the create event variables, 5 lines of code in the draw event, and 9 in the step event. I split those lines up into more so that it is much easier to read. In the draw event I typed a lot of extra explanation, just scroll down to find the actual code.

These objects all have the same code, so it is possible to make this even easier using parent objects.

My goal here is not just to provide a nice tool and elegant math to what I assume is a common problem. My goal is to make this incredibly easy to understand, if you have some triginometry knowledge that is. That way, this demo makes it possible to implement its core principles in just about any other project.


End User Licence Agreement (EULA).

Version 1.0.1. Published June 19, 2019

Age Rating: 12+

Average Rating

This asset hasn't received enough reviews yet.

Your review

You can only review assets you've bought.

No reviews yet

No reviews have been left for this asset - be the first!

Package contents

Loading, please wait

What is the issue?

Back to Top