Time for action — creating the score screen

To display the values of the highest scores, we will utilize the CreateHighScoreList method from Chapter 4, Game #3, CometCrusher, and make a few changes to it.

  1. For this, add a method called CreateScoreScreen to the game class.
    Method CreateScoreScreen:Int()
    
  2. Set the score layer as the default layer.
    eng.SetDefaultLayer(layerScore)
    
  3. Create a local text object to display the headline.
    Local txtTitleHightScore:ftObject = eng.CreateText(font1,"H I G H S C O R E S",cw/2,70.0,1)
    
  4. Start a FOR loop ranging from 1 to 10. This will be the factor that controls vertical placement of the list entries.
    For Local y:Int = 1 To 10
    
  5. Next, create a local text object that will display the entry number.
    Local txtScoreNum:ftObject = eng.CreateText(font1,"#"+y,(cw/4.0)+50.0,80.0 + (ch/20.0)*y)
    
  6. To display each entry of the list, create text objects that will be stored inside the text array we have defined at the beginning. Then close the FOR loop.
    txtHighScore[y-1] = eng.CreateText(font1,"0000000",(cw/4.0)*3.0-50.0,80.0 + (ch/20.0)*y,2)
    Next
    

    When the list is displayed, you want to provide a button for the user to use to go back to the menu.

  7. Insert a local text button set with the ID btnBack. Then, close the method.
    Local bt := CreateTextButton(font1, "Back", cw/2, ch-font1.Height(), btnBack, layerScore)
    Return 0
    End
    

What just happened?

With the last method, you can now create a high-score screen in your game.

Layer activation

In contrast to the games before, we have a few more layers. To switch every layer off and on each time you need to, it is better to create one method or function that does the dirty job for you.

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

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