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

What just happened?

Since we need to create several buttons in the game, we have created a method that will set them up for us. Later on, we can use the TouchCheck method to determine if a button was hit.

The info text objects

The game screen will have two text objects: One to display the game score and the other for the FPS value.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.216.7