Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

Time for action – resetting and changing levels


We'll need to create functions that set up the first and second levels in the game. If a level needs to be replayed, only the current level the user lost in can be accessed. Follow these steps to transition between the levels:

  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 then reset them:

      bricks:removeSelf()
    
      bricks.numChildren = 0
      bricks = display.newGroup()
  3. Remove alertDisplayGroup:

      alertBox:removeEventListener("tap", restart)
      alertDisplayGroup:removeSelf()
      alertDisplayGroup = nil
  4. Reset the ball and paddle positions:

      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
  5. Redraw the bricks for the current level:

    gameLevel1()
  6. Add an event listener to the background object for startGame(). Close the...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)