We'll need to create functions that set up the first and second level in the game. If a level needs to be replayed, only the current level the user lost in can be accessed.
Create a new function called
changeLevel1()
. This will be placed below theupdateBall()
function:function changeLevel1()
Clear the
bricks
group when the player loses the round and reset them:bricks:removeSelf() bricks.numChildren = 0 bricks = display.newGroup()
Remove the
alertDisplayGroup
:alertBox:removeEventListener("tap", restart) alertDisplayGroup:removeSelf() alertDisplayGroup = nil
Reset the
ball
andpaddle
position:ball.x = (display.contentWidth * 0.5) - (ball.width * 0.5) ball.y = (paddle.y - paddle.height) - (ball.height * 0.5) -2 paddle.x = display.contentWidth * 0.5
Redraw the
bricks
for the current level:gameLevel1()
Add an event listener to the
background
object forstartGame()
. Close the function.background:addEventListener("tap",...