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 — acting on timer events

To act on timer events, we need to detail the OnObjectTimer method inside the engine class. We will set the ID of an object to positive once again, and then check for collisions of its child collision circles:

  1. Check whether timerID is equal to g.tmObjSwitch.
    Method OnObjectTimer:Int(timerId:Int, obj:ftObject)
    If timerId = g.tmObjSwitch Then
    
  2. Get the object's ID and store it locally in the id variable.
    Local id:Int = obj.GetID()
    
  3. If id is negative, set it back to positive.
    If id < 0 Then obj.SetID(obj.GetID()*-1)
    
  4. Start a For loop now, for every child collision circle of the object.
    For Local i:Int = 1 To obj.GetChildCount()
    
  5. Do a collision check for each collision circle.
    g.eng.CollisionCheck(obj.GetChild(i))
    

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