local J=""local v=3 local L=4 local Y=v*L local b=229 local m=341 local N=12 assert((numImages*v)*L>=N)local S=1 assert(S>0)local R=0 local V=0 local Q=N/S local f=0 local function z(J)f=math.fmod(f+J,S)V=math.floor(f*Q)local v=R R=math.floor(V/Y)if v~=R then imageInstance.Image=imageAssetIDs[R+1]end local N=V-R*Y local z=math.floor(N/L)local s=N-z*L imageInstance.ImageRectOffset=Vector2.new(s*b,z*m)end Animator.Connection=nil Animator.Init=function()Animator.Connection=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(z)end Animator.Stop=function()if Animator.Connection then imageInstance.Image=J Animator.Connection:Disconnect()end end return Animator
-- Placeholder texture can be any roblox asset link
local initialTexture = ""

local RowCount = 3 -- rows in one sprite
local ColCount = 4 -- columns in one sprite
local perImageSpriteCount = RowCount * ColCount
local width = 229 -- image rect size
local height = 341

local framesInTotal = 12
assert(numImages * RowCount * ColCount >= framesInTotal)

local animPeriod = 1 -- period for the whole animation, in seconds
assert(animPeriod > 0)

local curImageIdx = 0
local curSpriteIdx = 0

local fps = framesInTotal / animPeriod
local accumulatedTime = 0

local function AnimateImageSpriteSheet(dt)
	accumulatedTime = math.fmod(accumulatedTime + dt, animPeriod)
	curSpriteIdx = math.floor(accumulatedTime * fps)

	local prevImageIndex = curImageIdx
	curImageIdx = math.floor(curSpriteIdx / perImageSpriteCount)
	if prevImageIndex ~= curImageIdx then
		imageInstance.Image = imageAssetIDs[curImageIdx + 1]
	end

	local localSpriteIndex = curSpriteIdx - curImageIdx * perImageSpriteCount
	local row = math.floor(localSpriteIndex / ColCount)
	local col = localSpriteIndex - row * ColCount
	imageInstance.ImageRectOffset = Vector2.new(col * width, row * height)
end

Animator.Connection = nil

Animator.Init = function()
	Animator.Connection = game:GetService("RunService").RenderStepped:Connect(AnimateImageSpriteSheet)
end

Animator.Stop = function()
	if Animator.Connection then
		imageInstance.Image = initialTexture
		Animator.Connection:Disconnect()
	end
end

return Animator
