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
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

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

Game #8, Treasure Chest 4. Close the method. Return 0 End What just happened? Again, we have implemented a method to create all the layers we need in the game. Our beloved play field--the background screen Now, we will define all the elements of 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. 1. 2. 3. 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. 4. 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 5. 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) [ 292 ]