The first thing we need to do is to have an actual image. We'll use the back of a tile from our Concentration game in this example, you can get it from the book's website, along with the full source code for this example.
To begin with, we need a layer. A layer groups together one or more Props and serves as a way to control rendering priorities between different Prop sets. For example, you can have one layer for the background and another one on top of it for the objects, and when you add a new Prop on the background layer, it will be displayed below the Props on the objects layer.
Note
MOAILayer
inherits from
MOAIProp
, so you can think of it as a Prop that groups other Props. You can call any of the methods of MOAIProp
on a layer.
In order to create a layer, you have to instantiate MOAILayer2D
as follows (type this below the viewport initialization in the code for Chapter 4, Our First Game with Moai):
First of all we create our layer:
layer = MOAILayer2D.new ()
We need to tell...