Time for action — detailing the OnUpdate method

The OnUpdate method will be called in the amount you have set the update rate to. The base script sets it to 60 times. Follow the given steps:

  1. Start a SELECT statement with gameMode as a parameter.
    Method OnUpdate:Int()
    Local d:Float = Float(eng.CalcDeltaTime())/60.0
    If isSuspended = False Then
    Select gameMode
    
  2. First, check if gameMode is equal to gmPlay:
    Case gmPlay
    eng.Update(d)
    
  3. Start a collision check for the game layer:
    eng.CollisionCheck(layerGame)
    
  4. Next, if there is a TouchHit method, do a touch check for the background layer:
    If TouchHit(0) Then
    eng.TouchCheck(layerBackGround)
    Endif
    
  5. Set the text property of the txtScore object to the current score value:
    txtScore.SetText("Score: "+score)
    
  6. Now, check whether the game mode is set to gmMenu:
    Case gmMenu
    
  7. If there is a touch hit, perform a touch check for the title layer:
    If TouchHit(0) Then
    eng.TouchCheck(layerTitle)
    Endif
    
  8. If the game mode is set to gmGameOver, update the background layer:
    Case gmGameOver
    eng.Update(layerBackGround, d)
    End
    Endif
    Return 0
    End
    

What just happened?

With detailing the OnUpdate method of the game class, we have the general control set of our game. When the game is not suspended, we check for touch hits, and then which touchable object of fantomEngine was hit. We also update objects depending on which mode the game is in.

At this stage, the game will look like the following screenshot:

What just happened?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.169.109