Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

4. Game Controls > Time for action – resetting and changing levels - Pg. 129

Chapter 4 Time for action ­ resetting and changing levels 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. 1. Create a new function called changeLevel1() . This will be placed below the updateBall() function: function changeLevel1() 2. Clear the bricks group when the player loses the round and reset them: bricks:removeSelf() bricks.numChildren = 0 bricks = display.newGroup() 3. Remove the alertDisplayGroup : alertBox:removeEventListener("tap", restart) alertDisplayGroup:removeSelf() alertDisplayGroup = nil 4. Reset the ball and paddle position: ball.x = (display.contentWidth * 0.5) - (ball.width * 0.5) ball.y = (paddle.y - paddle.height) - (ball.height * 0.5) -2