I am having trouble understanding the proper way to use timers when spawning multiple objects that each need a timer to run some function(s).
I am not sure the proper place to put the timer code and how to correctly call the function for each particular object.
For example, I am spawning some number of enemies with code like this and moving them to new locations:
local enemies = {} local function move(self) local newX, newY = getMoveLocation(self) transition.to(self, {time = 500, x=newX, y=newY}) end for i = 1, num\_enemies do local enemy = display.newSprite(sheet, sequences) enemy.x, enemy.y = getSpawnLocation() enemy.move = move enemy:move() enemies[i] = enemy display\_group:insert(enemy) end
I would like to have a timer which is called every so often which moves each enemy. I am having trouble knowing where to put the timer code and how to properly call the timer function for each enemy.
Can anyone help me out on the proper way to use a timer to do this?