How does the math for spritesheets work?

I’ve seen how awesome and overpowered spritesheets are and I want to start using them, however I don’t understand how the math behind it works.

How does it find the correct rectoffset and how does it move to other parts.

I would appreciate some sort of detailed explanation on how to start using them…

It is actually very easy. Rect Offset and Rect Scale are literally pixel offsets. Rect Scale draws a rectangle X, Y in size from the current Rect Offset. There is a main problem, however, and that is that most texture assets when uploaded to Roblox are resized so the pixel dimensions of the image change. The only current way I know of handling this is to upload images of the same size that Roblox uses or to check the size of the image that is uploaded onto the server. You can use any image editing software basically to figure out where the pixel values should be in order to encapsulate your items properly.
In this random example here, ignoring again the resize issues:


This is the size of roughly one of the sprites.

The goal of the script now is to move that rectangle across all of the sprites you need to use. In this case, when can use the Y based on their movement direction and the X based on time.
In more complicated spritesheets like the kind used in my GIF API, you have to go through the elements of a matrix in order, going from top-left to bottom-right until you have shown all the sprites.

This hasn’t been true in my experience. It shouldn’t be resized unless it’s over 1024 pixels wide (or tall), which is an awful lot for a spritesheet.

3 Likes