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

7. Game #6, At The Docks > Time for action — loading the level tiles

Time for action — loading the level tiles

To load a level, you will create a new method for it. Depending on how the field levelNum is set, it will load a corresponding text file into a string variable. This will then be split up so we can determine the ID of each tile.

  1. Create a new method inside the game class, called LoadLevel.
    Method LoadLevel:Int()
    
  2. Set the default layer for new objects, from now on, to layerGame.
    eng.SetDefaultLayer(layerGame)
    
  3. Remove all objects from the game layer, and reset the number of crates and the number that are on target.
    layerGame.RemoveAllObjects()
    crateNum = 0
    onTarget = 0
    
  4. Next, load the text file and store the result in the local String variable levelText.
    Local levelText:String = LoadString("level"+levelNum+".txt")
    

  

You are currently reading a PREVIEW of this book.

                                                                                        

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

  

Start a Free Trial