UNPKG

react-simple-game-engine

Version:

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

90 lines (89 loc) 3.4 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { copyProperties } from "../../utils"; import { Sprite } from "./sprite"; var AvatarSprite = /** @class */ (function (_super) { __extends(AvatarSprite, _super); function AvatarSprite() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._offset = { x: 0, y: 0, index: 0, width: 0, height: 0, }; return _this; } Object.defineProperty(AvatarSprite.prototype, "offset", { get: function () { return this._offset; }, enumerable: false, configurable: true }); AvatarSprite.prototype.onDraw = function () { if (this.source) { if (this.animation) { this.animation.draw(); } else { var _a = this._offset, x = _a.x, y = _a.y, width = _a.width, height = _a.height, index = _a.index; Renderer.image(this.source, // position on canvas 0, 0, this.width, this.height, //crop on source image index * width + x, y, width, height); } } }; AvatarSprite.prototype.initial = function (params) { var _a = (params || {}), offset = _a.offset, source = _a.source, _params = __rest(_a, ["offset", "source"]); if (source) { this._offset.width = source.width; this._offset.height = source.height; } if (offset) { copyProperties(this._offset, offset); } _super.prototype.initial.call(this, __assign(__assign({}, _params), { source: source })); }; return AvatarSprite; }(Sprite)); export { AvatarSprite };