local L=""local a=1 local h=2 local u=a*h local B=256 local E=384 local O=2 assert((numImages*a)*h>=O)local J=.5 assert(J>0)local k=0 local s=0 local C=O/J local d=0 local function i(L)d=math.fmod(d+L,J)s=math.floor(d*C)local a=k k=math.floor(s/u)if a~=k then imageInstance.Image=imageAssetIDs[k+1]end local O=s-k*u local i=math.floor(O/h)local z=O-i*h imageInstance.ImageRectOffset=Vector2.new(z*B,i*E)end Animator.Connection=nil Animator.Init=function()Animator.Connection=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(i)end Animator.Stop=function()if Animator.Connection then imageInstance.Image=L Animator.Connection:Disconnect()end end return Animator
-- Placeholder texture can be any roblox asset link
local initialTexture = ""

local RowCount = 1
local ColCount = 2
local perImageSpriteCount = RowCount * ColCount
local width = 256
local height = 384

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

local animPeriod = 0.5 -- 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
