O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — detailing the OnUpdate method

The OnUpdate method of the game class is responsible for calculating the delta time since the last frame and updating the game, depending on which mode it is in.

  1. Start a Select statement on the game mode.
    Method OnUpdate:Int()
    Local d:Float = Float(eng.CalcDeltaTime())/60.0
    If isSuspended = False Then
    eng.Update(Float(d))
    Select gameMode
    
  2. Check for the constant gmPlay.
    Case gmPlay
    
  3. Start a touch check on the game layer to determine which gems are selected.
    If eng.TouchHit(0) Then
    eng.TouchCheck(layerGame)
    Endif
    
  4. Check if there are no gems moving.
    If layerGame.GetObjTransCount()= 0 Then
    
  5. Fill up empty slots with new gems.
    FillTiles()
    
  6. Check if gems line up and clear them. Then, close the IF check.
    ClearGems() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required