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.
Thanks.

This thread might help: http://twolivesleft.com/Codea/Talk/discussion/1173/animated-images/p1

I posted a bit of code here about extracting animation from a sheet
http://twolivesleft.com/Codea/Talk/discussion/comment/10439#Comment_10439

HTH

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

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.