Game Development Reference
In-Depth Information
Figure 17-1. The rectangles indicate where you would like to add glitters in the game
The Constructor
Let's create a GlitterField class that allows you to add glitters to game objects. This class
inherits from the GameObject class, so you can easily attach it to the scene graph. The constructor
of the GlitterField class has several parameters. Here is the header and part of the body of the
constructor:
function GlitterField(density, width, height, layer, id) {
GameObject.call(this, layer, id);
this.width = width;
this.height = height;
// To do: initialize the glitter field
}
The first parameter is the density of the glitter field. This indicates how many glitters can be visible
at the same time. Then you have the width and height parameters, which indicate the size of the
rectangle. Finally, the layer and id parameters are passed to the base constructor. In the body of
the constructor, you store the width and height of the glitter field in member variables.
 
Search WWH ::




Custom Search