react-simple-game-engine
Version:
[WIP] not able to use in currently. <!-- Document cumming soon... -->
49 lines (48 loc) • 1.46 kB
JavaScript
var SimpleCamera = /** @class */ (function () {
function SimpleCamera() {
this._x = 0;
this._y = 0;
this.positionChangeListeners = [];
}
Object.defineProperty(SimpleCamera.prototype, "x", {
get: function () {
return this._x;
},
set: function (_x) {
this._x = _x;
this.emitPositionChangeEvent();
},
enumerable: false,
configurable: true
});
Object.defineProperty(SimpleCamera.prototype, "y", {
get: function () {
return this._y;
},
set: function (_y) {
this._y = _y;
this.emitPositionChangeEvent();
},
enumerable: false,
configurable: true
});
SimpleCamera.prototype.emitPositionChangeEvent = function () {
var listeners = this.positionChangeListeners;
for (var _i = 0, listeners_1 = listeners; _i < listeners_1.length; _i++) {
var listener = listeners_1[_i];
listener(this._x, this._y);
}
};
SimpleCamera.prototype.addPositionChangeListener = function (func) {
var listeners = this.positionChangeListeners;
listeners.push(func);
return function () {
var index = listeners.indexOf(func);
if (index > -1) {
listeners.splice(index, 1);
}
};
};
return SimpleCamera;
}());
export { SimpleCamera };