Time for action – activating the game

With all the game play elements set in place, it is time to get the application started by using the following steps:

  1. Create a new local function called gameActivate() and insert gameIsActive = true. Place the function above the moveChar() function:
        local gameActivate = function()
          gameIsActive = true
        end
  2. Initialize all the game actions by making a new function called gameStart():
        local gameStart = function()
  3. Start the physics property and set the gravity for the falling object:
          physics.start( true )
          physics.setGravity( 0, 9.8 )
  4. Activate all the functions instantiated. Add an event listener for the charObject, using the "accelerometer" event for the moveChar() function:
          drawBackground()
          createChar()
          eggTimer()
          hud()
          gameActivate()
          Runtime:addEventListener("accelerometer", moveChar)
        end
  5. Instantiate the gameStart() function and return the gameGroup group:
        gameStart()
        return gameGroup

If you remember, in the beginning of our code, we set gameIsActive = false. We will now change this status through the gameActivate() function and make gameIsActive = true. We made the gameStart() function apply all the initial game play elements. This includes the start of the physics engine and gravity. At the same time, we took the remainder of all the functions and initialized them.

Once all the functions are activated, gameGroup needs to be returned so that all the display objects appear during the game play.

To make sure that your physical object boundaries for your display objects are in the right place, use physics.setDrawMode( "hybrid" ) in the gameStart() function.

Q1. What retrieves or sets the text string of a text object?

Q2. What function converts any argument into a string?

Q3. What body type is affected by gravity and collisions with the other body types?