2016-06-29 13:48:30 -04:00
|
|
|
var util = require('util');
|
2016-06-29 23:07:34 -04:00
|
|
|
var MathUtil = require('../util/math-util');
|
2016-06-29 13:48:30 -04:00
|
|
|
var Target = require('../engine/target');
|
|
|
|
|
|
|
|
function Clone(spriteBlocks) {
|
|
|
|
Target.call(this, spriteBlocks);
|
2016-06-29 20:56:55 -04:00
|
|
|
this.drawableID = null;
|
|
|
|
this.initDrawable();
|
2016-06-29 13:48:30 -04:00
|
|
|
}
|
|
|
|
util.inherits(Clone, Target);
|
|
|
|
|
2016-06-29 20:56:55 -04:00
|
|
|
Clone.prototype.initDrawable = function () {
|
|
|
|
var createPromise = self.renderer.createDrawable();
|
|
|
|
var instance = this;
|
|
|
|
createPromise.then(function (id) {
|
|
|
|
instance.drawableID = id;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-29 13:48:30 -04:00
|
|
|
// Clone-level properties
|
|
|
|
Clone.prototype.x = 0;
|
|
|
|
|
|
|
|
Clone.prototype.y = 0;
|
|
|
|
|
|
|
|
Clone.prototype.direction = 90;
|
|
|
|
|
2016-06-29 20:56:55 -04:00
|
|
|
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);
|
2016-06-29 20:56:55 -04:00
|
|
|
self.renderer.updateDrawableProperties(this.drawableID, {
|
|
|
|
direction: this.direction
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-29 13:48:30 -04:00
|
|
|
module.exports = Clone;
|