Cleaning up animation frame counting

(Screenshot #1: old version with 0-based frame counting. Screenshot #2: new version with 1-based frame counting.)

When I first posted this, I had this niggle nagging at me about how the animation frame number was looping. I knew there was a better way to loop the frame number using modulus so that it went 1,2,3,4,5,6 instead of 0,1,2,3,4,5, thus requiring a +1 to the frame number any time you wanted to use it. I'm still not quite used to Lua's 1-based table indexing, so up until now I've never really had a need to loop back to 1 instead of 0 when using modulus.

But, when creating my next tutorial that's specifically about modulus, I stumbled across a great article showing cleanly how to do just what I was looking for. Perfect! It's not even that fancy or special. I just hadn't thought it through. But learning from others is what development is all about.

So now the cart has been updated, gif has been recaptured, and sample code has been updated to show the new, cleaner 1-based way of looping through the frame numbers.

Leave a comment

Log in with your account to leave a comment.