Since LimeJS uses Google to provide a class structure, we have the ability to define custom sprite objects. A custom sprite object is a class that inherits from Sprite or some other object. To setup inheritance, do three things:
- Include any necessary related objects using goog.provide
- Call the base constructor when creating the class, with a statement like “lime.Sprite.call(this);”
- Define the inheritance structure at the end via goog.inherits.
You can see a very simple example below:
As you can see, we can work with these custom sprites as a normal object, setting its properties and invoking it’s constructor using the new keyword. A sprite is an object that you would draw to the user interface, and therefore we want to add it to the layer (this.layer is a reference to a lime.Layer that’s added to the user interface already). And so we can see how we can use the object to render, but also work with an API of sorts.