Okay so I kind of am almost there but need a little push:
My dustbins spawn but there are a few to begin with like I want and then after about 30 seconds of the numbers of dustbins increasing there are 1000’s all clumped together… What can i do to alter my function so that its only ever a few at a time:
function spawnDustbin() dustbin = {} for i = 1,800 do dustbin[i] = display.newImage("dustbin.png") dustbin[i].xScale = 0.55 dustbin[i].yScale = 0.55 dustbin[i].y = 555 dustbin[i].x = (math.random(1000,1500) \* i) dustbin[i].speed = 4 physics.addBody( dustbin[i], "static", { friction=1.0, density=1.0, bounce=0, radius=30,} ) dustbin[i].enterFrame = moveDustbin Runtime:addEventListener("enterFrame", dustbin[i]) end end
and the movedustbin function simply moves the dustbin in the negative x direction:
function moveDustbin(self,event) if self.x \< -2560 then self.x = 2560 else self.x = self.x - val end end
First 20ish seconds: http://i.stack.imgur.com/7iEeP.png
After 20 seconds: http://i.stack.imgur.com/aae0D.png
Thank you very much James