Time for action — creating the title screen

This screen will show some graphics of our planes, the game title, and two instructional messages on how to start the game or exit it.

  1. To create the title screen, add a method called CreateTitleScreen to the game class.
    Method CreateTitleScreen:Int ()
    
  2. Set the default layer to layerTitle.
    eng.SetDefaultLayer(layerTitle)
    
  3. Next, create a box object covering the whole canvas. We want it to be white and that is its default color.
    Local box:ftObject = eng.CreateBox(cw,ch,cw/2,ch/2)
    
  4. Now, create a local text object for the game title. Place it in the center of the canvas and at one-fourth of the canvas height.
    Local tx1:ftObject = eng.CreateText(font1,"Air Dogs 1942",cw/2,ch/4,1)
    
  5. Scale the text object up by a factor of 2.0.
    tx1.SetScale(2.0)
    
  6. To inform the player about how to start the game, add a text object at the middle of the canvas.
    Local tx2:ftObject = eng.CreateText(font1,"Press 'P' to play",cw/2,ch/2+20, 1)
    
  7. To exit the game, we need to add another text object.
    Local tx3:ftObject = eng.CreateText(font1,"Press 'ESC' to end the game", cw/2,ch/2+120,1)
    
  8. We want to display both planes over the game title. Load a local image object with the player plane image.
    Local p1:ftObject = eng.CreateImage(atlas,0,0,64,64,cw/2-ch/8,ch/6)
    
  9. Rotate it to an angle of 45 degrees.
    p1.SetAngle(45)
    
  10. Now, load the enemy plane and rotate it to 315 degrees.
    Local p2:ftObject = eng.CreateImage(atlas,64,0,64,64,cw/2+ch/8,ch/6)
    p2.SetAngle(315)
    
  11. Close the method.
    Return 0
    End
    

What just happened?

We have created a method that will assemble the title/menu screen. Besides including some text objects, this time we also have some graphics for our title screen.

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

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