UNPKG

react-simple-game-engine

Version:

[WIP] not able to use in currently. <!-- Document cumming soon... -->

94 lines (93 loc) 3 kB
import { Animator } from "../animations/animator"; import { AvatarAnimationSprite } from "../animations/avatar.animation"; import { LogicComponent } from "../logic-component"; var Sprite = /** @class */ (function () { function Sprite() { } Object.defineProperty(Sprite.prototype, "animation", { get: function () { return this._animation; }, set: function (ani) { var _this = this; this._animation = ani; if (ani instanceof Animator) { ani.linkSprite(this); } else { if (this._animation instanceof AvatarAnimationSprite) { this._animation.onGetSource = function () { return _this.source; }; this._animation.onGetSize = function () { return ({ width: _this._width, height: _this._height, }); }; } } }, enumerable: false, configurable: true }); Object.defineProperty(Sprite.prototype, "animator", { get: function () { return this._animation; }, enumerable: false, configurable: true }); Object.defineProperty(Sprite.prototype, "entity", { get: function () { return this._entity; }, set: function (entity) { this._entity = entity; var _a = entity.getSpriteWidthHeight(), width = _a.width, height = _a.height; this._width = width; this._height = height; }, enumerable: false, configurable: true }); Object.defineProperty(Sprite.prototype, "width", { get: function () { return this._width; }, enumerable: false, configurable: true }); Object.defineProperty(Sprite.prototype, "height", { get: function () { return this._height; }, enumerable: false, configurable: true }); Sprite.prototype.draw = function () { var _this = this; var _a = this.entity, body = _a.body, position = _a.position, havePhysicBody = _a.havePhysicBody, scaleX = _a.scaleX, scaleY = _a.scaleY; Renderer.drawHandle(position, function () { if (havePhysicBody) { Renderer.rotate(body.angle); } Renderer.scale(scaleX, scaleY); _this.onDraw(); }); }; Sprite.prototype.initial = function (params) { if (params) { for (var key in params) { // @ts-ignore var P = params[key]; if (P instanceof LogicComponent) { // @ts-ignore this[key] = P.output(); } else { // @ts-ignore this[key] = P; } } } }; return Sprite; }()); export { Sprite };