Free Trial

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


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

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

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
      
      paddle.x = display.contentWidth * 0.5

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial