Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Game #8, Treasure Chest > Time for action — composing the background screen

Time for action — composing the background screen

Time for action — composing the background screen In the background screen, you will see a grid for all the gems. On the right side of the grid, you will also see the current score displayed, along with the time which is remaining to play this game. Insert a new method called CreateBackgroundScreen into the game class. Method CreateBackgroundScreen:Int () Set the default layer for this method. eng.SetDefaultLayer(layerBackground ) Start two new FOR loops—one for the rows (x) and one for the columns (y). For Local y:Int = 1 To rows For Local x:Int = 1 To columns In the next few pages, you will see the integer value 64 used many times. It is the length of the edge of all sprites that we will load. Now, load the grid sprite from the atlas image. The position will be set depending on the x and y values. Close both FOR loops. Local obj := eng.CreateImage(atlas,0,0,64,64,x*64,y*64) Next Next Next, add two text objects. One for the score and one for the time. Local tx1 := eng.CreateText(font1,"SCORE:",(columns+1)*64,32) Local tx2 := eng.CreateText(font1,"TIME:",(columns+1)*64,160) To display the actual score and time values, we need to add two more text objects, which will be set later in the game, at each frame. After that, close the method. txtScore = eng.CreateText(font1,score,(columns+1)*64,64) txtTime = eng.CreateText(font1,0,(columns+1)*64,192) Return 0 End What just happened? Another element of the the game is now ready to be created—the background layer. Once you call the method you have just implemented, it will create the background screen for you. Give it a name… the title screen Like all good games, we have a title screen to show too. Again, it's made just of text, but you could easily display an image, too.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint