hello i needed some help(alot of help) im a noobie and i m making a game the will go like this: so if my main file starts the menu and when i press the playBtn it starts the startgame.lua and when that starts i need just a white background and a blue ball and when the game starts the first ball spawns but when i press it its goes away and another one pops up using the code math.random and it keeps going and going im really stuck and need help thank you ask if you didnt get something thanks.
Just off the top of my head, this should do what you are looking for didn’t test it and used tap instead of touch because wasn’t sure what you were really going for
local function StartGame() local gameBG = display.newRect(0, 0, display.contentWidth, display.contentHeight) gameBG:setFillColor(1,1,1,1) gameBG.anchorX, gameBG.anchorY = 0, 0 gameBG.x, gameBG.y = 0, 0 local gameBall = nil local function SpawnBall() gameBall = display.newCircle(0,0,20,20,10) gameBall:setFillColor(0,0,1,1) gameBall.anchorX, gameBall.anchorY = 0.5, 0.5 local randomX, randomY = math.random(gameBall.width, (display.contentWidth - gameBall.width)), math.random(gameBall.height, (display.contentHeight - gameBall.height)) gameBall.x, gameBall.y = randomX, randomY function gameBall:tap( event ) timer.performWithDelay(1, function() gameBall:removeSelf() gameBall = nil SpawnBall() end, 1) return true end gameBall:addEventListener( "tap", gameBall ) end SpawnBall() end StartGame()
thank you!
Just off the top of my head, this should do what you are looking for didn’t test it and used tap instead of touch because wasn’t sure what you were really going for
local function StartGame() local gameBG = display.newRect(0, 0, display.contentWidth, display.contentHeight) gameBG:setFillColor(1,1,1,1) gameBG.anchorX, gameBG.anchorY = 0, 0 gameBG.x, gameBG.y = 0, 0 local gameBall = nil local function SpawnBall() gameBall = display.newCircle(0,0,20,20,10) gameBall:setFillColor(0,0,1,1) gameBall.anchorX, gameBall.anchorY = 0.5, 0.5 local randomX, randomY = math.random(gameBall.width, (display.contentWidth - gameBall.width)), math.random(gameBall.height, (display.contentHeight - gameBall.height)) gameBall.x, gameBall.y = randomX, randomY function gameBall:tap( event ) timer.performWithDelay(1, function() gameBall:removeSelf() gameBall = nil SpawnBall() end, 1) return true end gameBall:addEventListener( "tap", gameBall ) end SpawnBall() end StartGame()
thank you!