-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcamera.js
97 lines (75 loc) · 6.51 KB
/
camera.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Camera = void 0;
var _ticker = require("@pixi/ticker");
var _options = require("./options");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Camera that can be applied to a game/animation made with pixijs.
*/
var Camera = /*#__PURE__*/function () {
/**
* A reference to the options passed to camera pixi on initialization.
*
* @private
*
* @private {Options}
*/
/**
* A reference to the PIXI Ticker, if it's being used.
*
* @private
*
* @property {Ticker}
*/
/**
* @param {Ticker} [options] A reference to the PIXI Ticker, if it's being used.
*/
function Camera(options) {
_classCallCheck(this, Camera);
_defineProperty(this, "_options", void 0);
_defineProperty(this, "_ticker", void 0);
this._options = new _options.Options(options);
if (this._options.ticker) this._ticker = this._options.ticker;
}
/**
* Runs a provided effect.
*
* @param {Effect} effect The instance of the effect to run.
*/
_createClass(Camera, [{
key: "effect",
value: function effect(_effect) {
this._addToTicker(_effect);
}
/**
* Adds an effect to the PIXI Ticker if it's being used and removes it when necessary.
*
* @private
*
* @param {Effect} effect The effect to add to the Ticker.
*/
}, {
key: "_addToTicker",
value: function _addToTicker(effect) {
var _this = this;
var effectBound = effect.update.bind(effect);
if (this._ticker) {
var _this$_ticker2;
effect.finished.add(function () {
var _this$_ticker;
return (_this$_ticker = _this._ticker) === null || _this$_ticker === void 0 ? void 0 : _this$_ticker.remove(effectBound, _this);
});
(_this$_ticker2 = this._ticker) === null || _this$_ticker2 === void 0 ? void 0 : _this$_ticker2.add(effectBound, this, _ticker.UPDATE_PRIORITY.NORMAL);
} else effect.start();
}
}]);
return Camera;
}();
exports.Camera = Camera;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jYW1lcmEudHMiXSwibmFtZXMiOlsiQ2FtZXJhIiwib3B0aW9ucyIsIl9vcHRpb25zIiwiT3B0aW9ucyIsInRpY2tlciIsIl90aWNrZXIiLCJlZmZlY3QiLCJfYWRkVG9UaWNrZXIiLCJlZmZlY3RCb3VuZCIsInVwZGF0ZSIsImJpbmQiLCJmaW5pc2hlZCIsImFkZCIsInJlbW92ZSIsIlVQREFURV9QUklPUklUWSIsIk5PUk1BTCIsInN0YXJ0Il0sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7OztBQUVBOztBQUNBOzs7Ozs7Ozs7O0FBR0E7QUFDQTtBQUNBO0lBQ2FBLE07QUFDWDtBQUNGO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUFHRTtBQUNGO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUFHRTtBQUNGO0FBQ0E7QUFDRSxrQkFBWUMsT0FBWixFQUE4QjtBQUFBOztBQUFBOztBQUFBOztBQUM1QixTQUFLQyxRQUFMLEdBQWdCLElBQUlDLGdCQUFKLENBQVlGLE9BQVosQ0FBaEI7QUFDQSxRQUFJLEtB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