local p=""local n=4 local T=4 local y=n*T local x=256 local V=256 local b=15 assert((numImages*n)*T>=b)local F=1 assert(F>0)local B=0 local M=0 local I=b/F local G=0 local function Q(p)G=math.fmod(G+p,F)M=math.floor(G*I)local n=B B=math.floor(M/y)if n~=B then imageInstance.Image=imageAssetIDs[B+1]end local b=M-B*y local Q=math.floor(b/T)local c=b-Q*T imageInstance.ImageRectOffset=Vector2.new(c*x,Q*V)end Animator.Connection=nil Animator.Init=function()Animator.Connection=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(Q)end Animator.Stop=function()if Animator.Connection then imageInstance.Image=p Animator.Connection:Disconnect()end end return Animator

local initialTexture = ""

local RowCount = 4
local ColCount = 4
local perImageSpriteCount = RowCount * ColCount
local width = 256
local height = 256

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