Game Development Reference
In-Depth Information
Figure 8-2.
EaselJS online documentation with uninherited attributes listed in bold
You can further extend EaselJS classes yourself by using inheritance. As previously mentioned, you've come close
to this already by injecting custom attributes to display objects as you instantiate them. The following is a reminder of
how you've done this so far:
var orb = new createjs.Shape();
orb.graphics.beginFill('blue').drawCircle(0,0,20);
orb.points = 4;
orb.die = function(){
createjs.Tween.get(this).to({alpha:0},100).call(function(e){
stage.removeChild(this);
});
}
stage.addChild(orb);
This example creates a shape object named
orb
. It then proceeds to add extra behavior to the object that will
pertain to the game play. The
points
property and
die
method are not part of the
Shape
class, but by dynamically
injecting them into the instance, they are now accessible through the
orb
object.
someScore += orb.points;
orb.die();