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 — creating a gem

This method will create the corresponding image object, set the collision properties for the touch check, and return the object.

  1. Add the method CreateTile to the game class. The parameters are the x and y coordinates of the image object and its tile ID.
    Method CreateTile:ftObject(x:Int, y:Int, tile:Int = -100)
    
  2. Define a local object of the type ftObject.
    Local obj:ftObject
    
  3. If tile is set to -100, determine a random value ranging from 0 to 6.
    If tile = -100 Then tile = Rnd(6)
    
  4. Set the game layer as the default layer.
    eng.SetDefaultLayer(layerGame)
    

    We have six gem images on the sprite sheet. The tile parameter will not only set the object's tag property, but will also set the sprite coordinates.

  5. If tile equals 6, top it ...

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