function Cheese_AnimateTexCoords(texture, textureWidth, textureHeight, frameWidth, frameHeight, numFrames, elapsed, throttle) if ( not texture.frame ) then -- initialize everything texture.frame = 1; texture.throttle = throttle; texture.numColumns = floor(textureWidth/frameWidth); texture.numRows = floor(textureHeight/frameHeight); texture.columnWidth = frameWidth/textureWidth; texture.rowHeight = frameHeight/textureHeight; end local frame = texture.frame; if ( not texture.throttle or texture.throttle > throttle ) then local framesToAdvance = floor(texture.throttle / throttle); while ( frame + framesToAdvance > numFrames ) do frame = frame - numFrames; end frame = frame + framesToAdvance; texture.throttle = 0; local left = mod(frame-1, texture.numColumns)*texture.columnWidth; local right = left + texture.columnWidth; local bottom = ceil(frame/texture.numColumns)*texture.rowHeight; local top = bottom - texture.rowHeight; texture:SetTexCoord(left, right, top, bottom); texture.frame = frame; else texture.throttle = texture.throttle + elapsed; end end