This small library implements some CSS Flexbox features in JavaScript for use in Phaser 3.
The "Flex" object is a container inspired by the CSS Flexbox system, which facilitates the placement and alignment of objects (very useful for creating the GUI of our game).
Important: Still in early development phase.
Demo: https://jjcapellan.github.io/phaser3-flex/
Api: https://jjcapellan.github.io/phaser3-flex/docs/
npm i phaser3-flex
<script src="https://cdn.jsdelivr.net/gh/jjcapellan/phaser3-flex@0.1.0/dist/flex.min.js"></script>
Important: Package is exposed as global Fbx
<script type="module" src="https://cdn.jsdelivr.net/gh/jjcapellan/phaser3-flex@0.1.0/dist/flex.js"></script>
This is the most basic example:
import { Flex } from "phaser3-flex";
// Inside your Phaser.Scene ...
// Create a Flex object with default values
const flexContainer = new Flex(this);
// Create some content
const item1 = this.add.text(0, 0, "text1");
const item2 = this.add.image(0, 0, "image1");
const item3 = this.add.text(0, 0, "text2");
// Add content to the container
flexContainer.add(item1).add(item2).add(item3);
These are the container properties by default:
We can change all or some of this properties at creation time:
const flexContainer = new Flex(scene, { padding: 6, justifyContent: JustifyContent.SPACE_BETWEEN });
Some properties can be changed after Flex object creation:
flexContainer.setAlignItems(AlignItems.FLEX_END);
flexContainer.setY(100);
flexContainer.setWidth(400);
// ...
This library is licensed under the terms of the MIT open source license.
Generated using TypeDoc