phaser-jsx
Version:
Use JSX in Phaser.
30 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.render = render;
const helpers_1 = require("../helpers");
/**
* Renders a piece of JSX into a Phaser scene.
*
* @param element - Element that you want to display.
* @param scene - Phaser scene.
*/
function render(element, scene) {
(0, helpers_1.setScene)(scene);
// Detect if element is a function component for re-rendering
const componentType = element.type;
let componentFn = null;
let componentProps = null;
if (typeof componentType === 'function') {
const { prototype } = componentType;
if ((prototype === null || prototype === void 0 ? void 0 : prototype.constructor) !== componentType) {
// Function component
componentFn = componentType;
componentProps = element.props;
}
}
const context = (0, helpers_1.createRenderContext)(element, scene, componentFn, componentProps);
(0, helpers_1.setRenderContext)(context);
// Use rerender for initial render (gameObjectTree starts as null)
context.rerender();
}
//# sourceMappingURL=render.js.map