Time for action — creating the title screen

Inside the next method, we will set up the title screen. A colored box, a few text objects, and a timer that will switch the screen automatically to the menu screen, are all we need.

  1. Add the method CreateTitleScreen to the game class.
    Method CreateTitleScreen:Int()
    
  2. Set the default layer to layerTitle.
    eng.SetDefaultLayer(layerTitle)
    
  3. Create a dark gray box that is the size of the canvas.
    Local box := eng.CreateBox(cw,ch,cw/2,ch/2)
    box.SetColor(55,55,55)
    
  4. Add text objects to display the title of the game, its author, and the version number. The title will be scaled by a factor of 2.0.
    Local t1 := eng.CreateText(font1, strTitle, cw/2, ch/2-100, 3)
    t1.SetScale(2.0)
    Local t2 := eng.CreateText(font1, "by "+strAuthor, cw/2, ch/2, 3)
    Local t3 := eng.CreateText(font1, "Version "+strVersion, cw/2, ch/2+50, 3)
    
  5. To switch the screen automatically to the menu screen, we need to start an object timer. It will be attached to the box object, with the tmShowMenu ID and a time value of 3000 milliseconds. After setting it, close the method.
    eng.CreateObjTimer(b,tmShowMenu,3000)
    Return 0
    End
    

What just happened?

You have created a method that will set up the title screen. Because of the timer that is added, it will (once we have added more code later on) switch to the menu screen automatically. The title screen will look like the following screenshot in this game:

What just happened?

Game over… creating the "game over" screen

At one point of the game, when the time that was allowed is over, it should inform the player that the game is over. Let's create a method for this.

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

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