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 text buttons

This new helper method will be added to the game class:

  1. Insert a new class called CreateTextButton. Its parameters are a font object, the text, its position, button ID, and the layer that the button is added to.
    Method CreateTextButton:ftObject (font:ftFont, txt:String, xp:Int, yp:Int, id:Int, layer:ftLayer)
    
  2. Create a new next object.
    Local but:ftObject = eng.CreateText(font,txt,xp,yp,1)
    
  3. It its tag with the ID and the touch mode to a rectangular hit test.
    but.SetTag(id)
    but.SetTouchMode(2)
    
  4. Now, set the layer and close the method.
    but.SetLayer(layer)
    Return but
    End
    

What just happened?

With this method, we can easily add text buttons with one line of code. It is all about being more efficient when you develop games, ...

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