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 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 ...

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