So i have been fiddling around with this for a couple of hours now and can't find a suitable solution. What i want to is cut an image from a direction, i can't use resize
because that reduces the size of image relatively.
As far as i know, i believe that custom fonts work this way( if i even understand how they work), so is there a way to do this?
ImageRectSize
and ImageRectOffset
are what you're looking for.
For example, this image is a spritesheet with rectangles 75 pixels x 75 pixels in size.
First, set the ImageRectSize
to that, Vector2.new(75, 75)
, as that is the size of the rectangles.
Next comes the tricky part, as ImageRectOffset
is 0-based instead of 1-based.
For a typical spritesheet, every sprite is the exact same size. There are no awkwardly-sized sprites, so you can use this formula to find the correct ImageRectOffset
for a given sprite in a spritesheet:
image.ImageRectOffset = Vector2.new( (SPRITE_COL_NUMBER - 1)*image.ImageRectSize.X, --X (SPRITE_ROW_NUMBER - 1)*image.ImageRectSize.Y --Y )
So, for instance, if I want the top left sprite in that above sprite sheet, I would use Vector2.new(0, 0)
, since it is in column 1 and row 1.
If I wanted the yellow sword in the bottom left, I would use Vector2.new(0, 300)
, because (5 -1)*75 = 300
, and it is in column 1 and row 5.
The purple vase, which is in row 3 and column 4, then, would have an ImageRectOffset
of Vector2.new(225, 150)
As a side note, ROBLOX iirc allows image uploads of up to 2048 px by 2048 px in size, so make sure your sprite sheets are below that.
Also, that image is a Decal Image, not a Decal. The decal page shows the image stretched to 420x420, which is obviously not the correct dimensions, so make sure you're checking the right page to see if the image is being uploaded properly or not.