local s=""local Z=5 local A=3 local M=Z*A local H=320 local h=200 local u=26 assert((numImages*Z)*A>=u)local q=1 assert(q>0)local E=0 local r=0 local v=u/q local Q=0 local function D(s)Q=math.fmod(Q+s,q)r=math.floor(Q*v)local Z=E E=math.floor(r/M)if Z~=E then imageInstance.Image=imageAssetIDs[E+1]end local u=r-E*M local D=math.floor(u/A)local I=u-D*A imageInstance.ImageRectOffset=Vector2.new(I*H,D*h)end Animator.Connection=nil Animator.Init=function()Animator.Connection=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(D)end Animator.Stop=function()if Animator.Connection then imageInstance.Image=s Animator.Connection:Disconnect()end end return Animator

local initialTexture = ""

local RowCount = 5 
local ColCount = 3
local perImageSpriteCount = RowCount * ColCount
local width = 320
local height = 200

local framesInTotal = 26
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
