scratch-vm/src/sprites/sprite.js
2016-08-31 11:30:09 -04:00

51 lines
1.3 KiB
JavaScript

var Clone = require('./clone');
var Blocks = require('../engine/blocks');
/**
* Sprite to be used on the Scratch stage.
* All clones of a sprite have shared blocks, shared costumes, shared variables.
* @param {?Blocks} blocks Shared blocks object for all clones of sprite.
* @constructor
*/
function Sprite (blocks) {
if (!blocks) {
// Shared set of blocks for all clones.
blocks = new Blocks();
}
this.blocks = blocks;
/**
* Human-readable name for this sprite (and all clones).
* @type {string}
*/
this.name = '';
/**
* List of costumes for this sprite.
* Each entry is an object, e.g.,
* {
* skin: "costume.svg",
* name: "Costume Name",
* bitmapResolution: 2,
* rotationCenterX: 0,
* rotationCenterY: 0
* }
* @type {Array.<!Object>}
*/
this.costumes = [];
/**
* List of clones for this sprite, including the original.
* @type {Array.<!Clone>}
*/
this.clones = [];
}
/**
* Create a clone of this sprite.
* @returns {!Clone} Newly created clone.
*/
Sprite.prototype.createClone = function () {
var newClone = new Clone(this);
this.clones.push(newClone);
return newClone;
};
module.exports = Sprite;