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 — creating buttons

As we have several buttons in the game, we will add a method to the game class that will set up a button for us:

  1. Insert the CreateButton method into the game class. Its parameters are the button width and height, its position, layer and an ID.
    Method CreateButton:Int (width:Int, height:Int, xp:Int, yp:Int, id:Int, layer:ftLayer)
    
  2. Create a new ZoneBox via the CreateZoneBox statement.
    Local but:ftObject = eng.CreateZoneBox(width, height, xp, yp)
    
  3. To identify the button, later in the OnObjTouch event of the engine, we will set the tag property of the object with the ID.
    but.SetTag(id)
    
  4. Now, set the touch mode (collision detection) to use the bounding box.
    but.SetTouchMode(2)
    
  5. Lastly, set the layer and then close the method ...

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