With all the game play elements set in place, it is time to get the application started by using the following steps:
gameActivate()
and insert gameIsActive = true
. Place the function above the moveChar()
function:local gameActivate = function() gameIsActive = true end
gameStart()
:local gameStart = function()
physics.start( true ) physics.setGravity( 0, 9.8 )
charObject
, using the "accelerometer"
event for the moveChar()
function:drawBackground() createChar() eggTimer() hud() gameActivate() Runtime:addEventListener("accelerometer", moveChar) end
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?
object.text
object.size
object:setTextColor()
Q2. What function converts any argument into a string?
tonumber()
print()
tostring()
nil
Q3. What body type is affected by gravity and collisions with the other body types?