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 thegame
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
but.SetLayer(layer) Return 0 End