src code

constructor new Sprite

new Sprite(spriteset[, options])
  • spriteset (Spriteset) – The spriteset for this Sprite to use. This is final once instantiated, and cannot be changed.
  • options (Object) – The optional 'options' object's properties are copied this Sprite in the constructor. It allows all the same default properties as Component, but also adds Sprite#spriteX and Sprite#spriteY.

Instantiates a new Sprite based on the given Spriteset. It's more common, however, to make your own subclass of Sprite in your game code. For example:

var AlienClass = Class.create(Sprite, {
    initialize: function($super, options) {
        $super(AlienClass.sharedSpriteset, options);
    },
    update: function($super) {
        // Some cool game logic here...
        $super();
    }
});
 AlienClass.sharedSpriteset = new Spriteset("alien.png", 25, 25);

Here we are creating a Sprite subclass called AlienClass that reuses the same Spriteset object for all instances, and centralizes logic code by overriding the Component#update method.