Iterating through a character sprite sheet help

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.

This thread might help:

I posted a bit of code here about extracting animation from a sheet


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
    yanim=4 --row of sprites to display starting from the bottom
    numacross=4 --number of columns of sprites
    numdown=4 --number of rows of sprites

function draw()
    background(40, 40, 50)  
    m:setRectTex(recti,xanim*(1/numacross), yanim*(1/numdown),(1/numacross),(1/numdown))
    if animdelay>animspeed then
    xanim = xanim + 1
    if xanim>numacross-1 then
    animdelay = animdelay + 1       

It might be the row selection - have you tried setting yanim to 0,1,2 or 3?

yanim=4 starts at the top of your 512 image and goes up by 128 px

Got it, used readImage() instead of sprite() to load the image and it worked fine, thanks.