Hey folks, so I'm trying to build a menu slide-in/slide-out animation for an arbitrary number of menu rows. The effect I want is effectively each row sliding in from the right hand side, with a very slight 50-100ms offset increasing per row, to create a sort of "wave" effect.
I'm new to Lua so I'm struggling with how to structure this. I'm using animator.new to set up my animations, and I think what I want to do is have a for loop that iterates through the number of rows while drawing them (which is working already), and adds a new animator per row, where the name of that animator includes the number of the row.
e.g. (excuse simplified pseudocode)
rowNumber = i
animRow1 = animator.new(..., rowNumber*100)
So my first question is, is this how you'd approach the problem? And the second is, how do I increase the number in the name of a variable based on "i"?
I recommend storing those animators in a list (table), indexed by their row number.
-- outside the loop
local rowAnimators = {}
-- inside the loop
rowAnimators[i] = animator.new(..., i*100)
You can access them later using the same syntax you use to set them, in order to check their current value, etc.
Edit: to add a clarification, you’ll want to create your animators in response to the event which causes the menu to appear/disappear. You don’t want the animator.new call inside your draw loop or the animation will never have a chance to begin. Inside the draw loop is where you want to access them again to read their value, e.g.
local x = rowAnimators[i]:currentValue()
-- draw using the interpolated x value for the row