scratch-vm/src/sprites/clone.js

43 lines
1,020 B
JavaScript
Raw Normal View History

var util = require('util');
2016-06-29 23:07:34 -04:00
var MathUtil = require('../util/math-util');
var Target = require('../engine/target');
function Clone(spriteBlocks) {
Target.call(this, spriteBlocks);
this.drawableID = null;
this.initDrawable();
}
util.inherits(Clone, Target);
Clone.prototype.initDrawable = function () {
var createPromise = self.renderer.createDrawable();
var instance = this;
createPromise.then(function (id) {
instance.drawableID = id;
});
};
// Clone-level properties
Clone.prototype.x = 0;
Clone.prototype.y = 0;
Clone.prototype.direction = 90;
Clone.prototype.setXY = function (x, y) {
this.x = x;
this.y = y;
self.renderer.updateDrawableProperties(this.drawableID, {
position: [this.x, this.y]
});
};
Clone.prototype.setDirection = function (direction) {
2016-06-29 23:07:34 -04:00
this.direction = MathUtil.wrapClamp(direction, -179, 180);
self.renderer.updateDrawableProperties(this.drawableID, {
direction: this.direction
});
};
module.exports = Clone;