O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required