I have a 128px 4x4 character sprite sheet with a burning torch animation, I looking for a way to
Loop through the different frames of the sheet.
I have scanned the forum and haven’t really found a solid way of doing this, it looks like the best way would be to use the
“mesh.textCoords” function and offset the coordinates for each frame in the animation then looping back to the
First again. My problem is I understand the theory but need a push in the right direction, anyCode snippets or ideas
would be very welcome.
Thanks.
Thats great West thanks!
I’ve tried it with a 512px .png, with 128x128 images, making it 4 by 4 from my Dropbox
But I’m just getting a white box, heres your code with my changes, am I missing something?
function setup()
m = mesh()
m.texture = sprite("Dropbox:zomb") --sprite sheet
recti = m:addRect(WIDTH/2,HEIGHT/2,128,128)
parameter("animspeed", 1, 10, 6) --user defined animation speed
xanim=0
yanim=4 --row of sprites to display starting from the bottom
animdelay=0
numacross=4 --number of columns of sprites
numdown=4 --number of rows of sprites
end
function draw()
background(40, 40, 50)
noSmooth()
m:setRectTex(recti,xanim*(1/numacross), yanim*(1/numdown),(1/numacross),(1/numdown))
if animdelay>animspeed then
xanim = xanim + 1
animdelay=0
end
if xanim>numacross-1 then
xanim=0
end
animdelay = animdelay + 1
m:draw()
end