2016-06-29 13:48:30 -04:00
|
|
|
var Clone = require('./clone');
|
|
|
|
var Blocks = require('../engine/blocks');
|
|
|
|
|
2016-07-06 14:09:06 -04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2016-08-31 11:21:32 -04:00
|
|
|
function Sprite (blocks, name) {
|
2016-06-29 13:48:30 -04:00
|
|
|
if (!blocks) {
|
|
|
|
// Shared set of blocks for all clones.
|
|
|
|
blocks = new Blocks();
|
|
|
|
}
|
|
|
|
this.blocks = blocks;
|
2016-08-31 11:21:32 -04:00
|
|
|
this.name = name;
|
|
|
|
this.costumes = [];
|
2016-06-29 13:48:30 -04:00
|
|
|
this.clones = [];
|
|
|
|
}
|
|
|
|
|
2016-07-06 14:09:06 -04:00
|
|
|
/**
|
|
|
|
* Create a clone of this sprite.
|
|
|
|
* @returns {!Clone} Newly created clone.
|
|
|
|
*/
|
2016-06-29 20:56:55 -04:00
|
|
|
Sprite.prototype.createClone = function () {
|
2016-08-31 11:21:32 -04:00
|
|
|
var newClone = new Clone(this);
|
2016-06-29 20:56:55 -04:00
|
|
|
this.clones.push(newClone);
|
|
|
|
return newClone;
|
|
|
|
};
|
|
|
|
|
2016-06-29 13:48:30 -04:00
|
|
|
module.exports = Sprite;
|