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 a method to update the text information

To update these text objects, we will create the UpdateInfoText method. Each text object has a text field that stores the text string value. The content of this field will be drawn on the screen.

  1. Add a new method called UpdateInfoText to the game class.
    Method UpdateInfoText:Int()
    
  2. Set the text fields of both objects corresponding to their purpose.
    txtScore.SetText("Score: "+score)
    txtFPS.SetText("FPS: "+fps)
    
  3. Close the method.
    Return 0
    End
    

What just happened?

Since we created a separate method to update the info text objects, we can call it at any time we wish. Later on, we will do this in the OnUpdate event on the game class, but the OnRender event would be good, too.

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