I can't seem to get this to work. It only draws one dot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function Star:new() local Star = display.newImage('star.png') function Star:follow() local Starcopy = self function Star:followMe() local num = 0 if Starcopy.dots then num = #Starcopy.dots end local dot = display.newCircle( Starcopy.x, Starcopy.y, 30 ) Starcopy.parent:insert(dot) Starcopy.dots[num + 1] = dot end self.timer = timer.performWithDelay(50, followMe, 0) end return Star end local sky = display.newGroup() local Orion = Star:new() sky:insert(Orion) Orion.x = 50; Orion.y = 50 Orion:follow() transition.to(Orion, {x = 1000, y = 1000, time = 8000}) |
Not getting the full picture from the code that you posted...
Have a few missing links...
what is Star ?
where is the end for function new() ?
function new() does not return any value to pass to variable Orion
can you post a fully working code for this ? the one with which you managed to print a single dot...
Thanks for the reply and point out my messiness. I edited the post with a solution. My problem was that in:
self.timer = timer.performWithDelay( 50, self.followMe, 0)
The self next to followMe refers to the timer and not star. And then:
self.timer = timer.performWithDelay( 50, self:followMe(), 0 )
Self refers to the star but this form, self:followMe(), is not correct for the timer to perform the same function in iterations.
The solution is to create a local copy of the star and then call it as an upvalue in the followMe() function.