Hi all,
I have been following an YouTube tutorial, and I had a quick question on the code.
Basically, I want to have multiple color balls spawn from random locations outside the screen and move towards the center. I have a code that works in spawning one ball and moving towards the center, however I do not know how do make it re-spawn continually with the random colored balls (each their own object). Right now the ball is only spawned once, and it is pretty much done after that.
function spawnBall() local ball1 = display.newRoundedRect( 10, 10, 10, 10, 5 ) ball1.x = 0 ball1.y = 0 ball1:setFillColor( 1, 1, 1 ) local ball2 = display.newRoundedRect( 10, 10, 10, 10, 5 ) ball2.x = 0 ball2.y = 0 ball2:setFillColor( 1, 0, 1 ) if math.random(2) == 1 then ball1.x = math.random ( -100, -10 ) else ball1.x = math.random ( display.contentWidth + 10, display.contentWidth + 100 ) ball1.xScale = -1 end ball1.y = math.random ( display.contentHeight ) ball1.trans = transition.to ( ball1, { x=centerX, y=centerY, time=math.random( 2500-speedBump, 4500-speedBump) } ) speedBump = speedBump + 50 end spawnBall()
Also, is there a way to detect when the ball hits an object so that I can trigger different events based off of it?
Thanks 