My Spritesheet animation doesnt work as expected

So i made a animation in image label using spritesheet (one image) but the code isnt working properly,here is a video showing the problem:
robloxapp-20210829-1611492.wmv (419.4 KB)
here is what i need :
a_f1631cbaa516447c310b07887c4c70d0
as you can see the animation has kind of a lag effect which i dont want
my spritesheet is 900x1100 pixels with 100x100 each tile and it doesnt have any padding in each tile and there are 9 tiles in x and 11 tiles in y axis

here is my code im using

local line = 0
while true do
	for i=1,9,1 do
		wait()
		script.Parent.ImageRectOffset += Vector2.new(90,0)
	end
	script.Parent.ImageRectOffset = Vector2.new(0,0)
	script.Parent.ImageRectOffset += Vector2.new(0,90*line)
	line +=1 
	if line == 11 then
		line = 0
		script.Parent.ImageRectOffset = Vector2.new(0,0)
		script.Parent.ImageRectOffset += Vector2.new(0,90*line)
	end
end

pls dont judge the code i know it sucks

2 Likes

:wave: Hello!

The way I ended up doing a spritesheet when I was making an Ariana Grande fan game was creating a frame aspect ratio as the original image, setting clip descendants to true, then having the sprite sheet as a child of the frame with the following size: #Colums, 0, #Rows, 0.

Then, I used the following code!
Please note that I believe you can acomplish what you’re looking for very easily with TweenService. Take a look at the documentation here: TweenService
The reason you should use TweenService is for a higher quality, more stable image with smoother animations.

local Columns = 5
local Rows = 8

local Column = 1
local Row = 1

local ColumnOffset = 3

while wait(.05) do
	local Position = UDim2.fromScale(-(Column-1), -(Row-1))
	script.Parent.ImageLabel.Position = Position
	
	Column += 1
	
	if (Column > Columns) or (Row == Rows and Column == Columns-ColumnOffset) then 
		Column = 1 Row += 1 
	end
	if Row > Rows then Row = 1 end
end

4 Likes

thanks ill try it out soon when i can

2 Likes

may i know something,is the collumns left to right or top to bottom?

Colum is left to right, row is top to bottom.

thats so sad your code didnt work at all ;(

thanks i figured it out i just had to make the image label size same as the real resolution

1 Like