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-30 00:11:47 -04:00
|
|
|
Clone.prototype.size = 100;
|
|
|
|
|
|
|
|
Clone.prototype.effects = {
|
|
|
|
'color': 0,
|
|
|
|
'fisheye': 0,
|
|
|
|
'whirl': 0,
|
|
|
|
'pixelate': 0,
|
|
|
|
'mosaic': 0,
|
|
|
|
'brightness': 0,
|
|
|
|
'ghost': 0
|
|
|
|
};
|
|
|
|
|
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-30 00:11:47 -04:00
|
|
|
Clone.prototype.setSize = function (size) {
|
|
|
|
this.size = MathUtil.clamp(size, 5, 535);
|
|
|
|
self.renderer.updateDrawableProperties(this.drawableID, {
|
|
|
|
scale: this.size
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Clone.prototype.setEffect = function (effectName, value) {
|
|
|
|
this.effects[effectName] = value;
|
|
|
|
var props = {};
|
|
|
|
props[effectName] = this.effects[effectName];
|
|
|
|
self.renderer.updateDrawableProperties(this.drawableID, props);
|
|
|
|
};
|
|
|
|
|
|
|
|
Clone.prototype.clearEffects = function () {
|
|
|
|
for (var effectName in this.effects) {
|
|
|
|
this.effects[effectName] = 0;
|
|
|
|
}
|
|
|
|
self.renderer.updateDrawableProperties(this.drawableID, this.effects);
|
|
|
|
};
|
|
|
|
|
2016-06-29 13:48:30 -04:00
|
|
|
module.exports = Clone;
|