position of the panel's left edge
position of the panel's top edge
see UIPanelSettings
Define the renderable opacity
Set to zero if you do not wish an object to be drawn
Opacity cascades: it is multiplied with the alpha already on the
renderer, so fading a Container fades everything inside it,
and a child at alpha 0.5 inside a parent at 0.5 draws at 0.25.
Each renderable keeps its own value — the composition happens at
draw time, and is undone when the renderable is done.
That is different from Container#setChildsProperty, which
assigns a value onto the children themselves. Use alpha to fade a
subtree, and setChildsProperty to change what the children are.
Whether the renderable object will always update, even when outside of the viewport
a reference to the parent object that contains this renderable
The anchor point is used for attachment behavior, and/or when applying transformations.
The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner

a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.
Note: Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
To specify a value through Tiled, use a json expression like json:{"x":0.5,"y":0.5}, or (since 19.9) a plain string preset such as bottom.
At construction time, settings.anchorPoint also accepts the named presets
"center", "top", "bottom", "left", "right", "top-left", "top-right",
"bottom-left", "bottom-right" on every renderable that consumes it
(Sprite, Entity, Collectable, ImageLayer, Text, BitmapText, Sprite3d and subclasses).
Note: a body's collision shapes are measured from the same frame this
places the renderable in, so a shape of Rect(0, 0, width, height) covers the
renderable whatever the anchor is (since 20.7; before that shapes were measured
from pos regardless, and a non-corner anchor collided where it was not drawn).
A shape's own pos still offsets it inside that frame. A renderable that has
cleared Renderable#applyAnchorTransform takes no offset at all, on the
drawing or on its shapes. Note also that the adapters read the anchor when the
body is created, so changing it afterwards moves the drawing but not an
already-built body.
Whether Renderable#preDraw applies the Renderable#anchorPoint offset to the renderer transform.
When true (the default), the renderable is shifted by
-anchorPoint × (width, height) so its anchor — not its top-left
corner — aligns with its position. Correct for sprites and other 2D
renderables.
Set to false for a renderable that emits its own final world
coordinates and takes its origin from geometry rather than a bounds
box — e.g. a Mesh on the Camera3d world-space path (a 3D
mesh is positioned by its transform and has no anchor). The WebGL mesh
batcher reuses this same renderer transform as its view matrix,
so applying the normalized anchor there would shift every mesh by
half its OWN bounds box; because scene meshes size that box per node,
props and the platforms they rest on would drift apart and overlap.
Specify if the children z index should automatically be managed by the parent container
Specify if the children list should be automatically sorted when adding a new child
When enabled, an object container will automatically apply any defined transformation before calling the child draw method.
// enable "automatic" transformation when the object is activated
onActivateEvent: function () {
// reset the transformation matrix
this.currentTransform.identity();
// ensure the anchor point is the renderable center
this.anchorPoint.set(0.5, 0.5);
// enable auto transform
this.autoTransform = true;
....
}
define a background color for this container
the blend mode to be applied to this renderable — any of the modes listed on CanvasRenderer#setBlendMode, honoured identically by every renderer
whether it swallows pointer events aimed at what is behind it
How far the panel drifts up and down, in pixels. 0, the default,
leaves it still.
The slow float an idle dialogue or pause panel has in a lot of games, which is there so a screen waiting for input does not look frozen. It is a sine, so this is the distance to either extreme and the panel covers twice it over a cycle; 2 to 4 is the usual range, and it starts by rising rather than sinking.
Do not go much below 2. The renderer snaps a translation to whole pixels, truncating, so an amplitude of 1 spends most of the cycle reading as 0 and the panel twitches rather than drifts.
The panel is CLICKABLE where it is drawn: the offset goes into
UIPanel#getAbsolutePosition, which is what the bounds pipeline
reads, so the hit area of the panel and of every widget inside it
follows the float at any depth. pos is deliberately left alone, so a
caller still reads and writes the resting place rather than a value
that moves under them.
The bounds are rebuilt only on the frames the offset actually changes, so a panel with no bob costs nothing.
How long one full up and down cycle takes, in milliseconds.
Anything at or below zero turns the bob off rather than dividing by it.
That is not politeness: the offset would be NaN, and one translate
by NaN writes it into the transform, where every batched vertex under
it inherits the poison and the GPU clips the lot away. A panel that
silently vanished would be a long way from an obviously bad period.
the renderable physics body — the handle returned by the
active PhysicsAdapter's addBody (or constructed
imperatively via new Body(...)). Typed as the portable
PhysicsBody interface; cast to the adapter-specific
concrete type (MatterAdapter.Body, BuiltinAdapter.Body, or
the legacy Body class) to reach native fields.
// define a new Player Class
class PlayerEntity extends me.Sprite {
// constructor
constructor(x, y, settings) {
// call the parent constructor
super(x, y , settings);
// define a basic walking animation
this.addAnimation("walk", [...]);
// define a standing animation (using the first frame)
this.addAnimation("stand", [...]);
// set the standing animation as default
this.setCurrentAnimation("stand");
// add a physic body
this.body = new me.Body(this);
// add a default collision shape
this.body.addShape(new me.Rect(0, 0, this.width, this.height));
// configure max speed, friction, and initial force to be applied
this.body.setMaxVelocity(3, 15);
this.body.setFriction(0.4, 0);
this.body.force.set(3, 0);
this.isKinematic = false;
// set the display to follow our position on both axis
app.viewport.follow(this, app.viewport.AXIS.BOTH);
}
...
}
Declarative body definition consumed by the active
PhysicsAdapter when this renderable is added to a
container. Adapter API only — leave undefined if you
build a body imperatively via this.body = new Body(...).
When set, the parent container forwards it to
world.adapter.addBody(this, this.bodyDef), which constructs
the underlying physics body (matter, builtin SAT, …) and
assigns the engine-portable wrapper to this.body. This is
the engine-portable path: the same bodyDef produces an
equivalent body under any adapter.
Typical fields: type ("static"/"dynamic"/"kinematic"),
shapes, collisionType, collisionMask, restitution,
frictionAir, density, gravityScale, isSensor,
maxVelocity, fixedRotation. See BodyDefinitionInit.
shapes is normally a list of collision shapes, but it can also
name a collision shape file preloaded as JSON, paired with id
naming the body to read out of it. The file is resolved before any
adapter sees the definition, so the same one works unchanged on
every backend.
// a shape authored in code
this.bodyDef = {
type: "dynamic",
shapes: [new me.Rect(0, 0, this.width, this.height)],
};
// shapes drawn in a physics-shape editor, preloaded as JSON with
// { name: "shapes", type: "json", src: "data/physics/shapes.json" }
this.bodyDef = { type: "dynamic", shapes: "shapes", id: "hotdog" };
// the density, friction and bounce the shapes were authored with
// come with them, unless the definition states otherwise (each is
// honoured by whichever backends support it):
this.bodyDef = {
type: "dynamic",
shapes: "shapes",
id: "hotdog",
restitution: 0.9, // wins over whatever the file carries
};
drawn around the edge; null for none
how thick that border is
Specify if the container draw operation should clip its children to its own bounds
OptionalcollisionOptionalcollisionOptional per-shape collision settings, honoured by Body#addShape
and defaulted there. Declared rather than initialized: the body writes
them when the shape joins it, so a class field here would emit an
undefined own property on every shape ever built. See addShape for
the table of defaults and what each one does.
the renderable transformation matrix (4x4).
For standard 2D use, only the 2D components are used (rotate around Z, scale X/Y, translate X/Y).
For 3D use (e.g. Mesh), the full 4x4 matrix supports rotation around any axis,
3D translation, and perspective projection.
Use the rotate(), scale(), and translate() methods rather than modifying this directly.
The edges here are the direction of the nth edge of the polygon, relative to
the nth point. If you want to draw a given edge from the edge value, you must
first translate to the position of the starting point.
Re-measure this container's bounds from its children whenever a child's bounds change. Expensive — every update walks the whole child list — and off by default, because a parent almost never needs it.
Enable it for a group whose extent genuinely IS its members' union and moves as they do: a flock of birds, a squad of enemies. A container whose size is known (or fixed) should be given that size with Renderable#resize instead, which costs nothing per frame — that is what GLTFModel does, from the glTF scene's own bounding box.
Note that a container with neither — no dimensions of its own and
this left off — reports an EMPTY bounds (min +Infinity, max
-Infinity), since Container#updateBounds then has nothing
to measure. Anything reading it is wrong about where the container
is, and the physics broadphase, which files every item by
getBounds(), cannot place it at all.
the fill behind the children; null leaves it transparent
UI base elements use screen coordinates by default (Note: any child elements added to a UIBaseElement should have their floating property to false)
(G)ame (U)nique (Id)entifier"
a GUID will be allocated for any renderable object added
to an object container (including the app.world container)
Tap and hold threshold timeout in ms
true if the pointer is over the object
a list of indices for all vertices composing this polygon, filled in by Polygon#getIndices and invalidated by Polygon#recalc.
A subclass may repurpose this name for geometry of its own: a
Mesh holds a GPU index buffer here, a typed array rather than a
plain one. recalc therefore only clears the slot when it owns it —
anything else reading it should check what it got.
Optionalisfalse takes this shape out of collision without removing it
object can be clicked or not
when true the renderable will be redrawn during the next update cycle
object can be dragged or not
object can be tap and hold
If true then physic collision and input events will not impact this renderable
make the renderable object persistent over level changes
Optionalistrue reports contacts but skips the position correction
A mask limits rendering elements to the shape and position of the given mask object. So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
The name of the renderable
a callback to be extended, triggered after a child has been added or removed
an event handler that is called when the renderable leave or enter a camera viewport
Array of points defining the Polygon
Note: If you manually change points, you must call recalcafterwards so that the changes get applied correctly.
origin point of the Polygon
whether a single post effect on this renderable needs an offscreen capture instead of the renderer's shader-swap fast path.
One effect is normally applied by drawing the renderable with the
effect's own program rather than capturing and post-processing it,
which costs no render target. That is only equivalent when everything
the renderable draws is a textured quad. fillRect and the shape
dispatch go through a batcher that never looks at that shader, so a
single effect on a renderable that draws with primitives silently
does nothing. Set this and the capture is used instead, at the cost
of a render target while the effect is active.
Two or more effects always capture, so this only ever changes the single-effect case.
the list of post-processing shader effects applied to this renderable (GPU backends — WebGL and WebGPU). Effects are applied in order. Use addPostEffect, getPostEffect, and removePostEffect to manage effects, or assign directly. On the Canvas renderer effects stay inert (the scene keeps rendering un-effected).
corner radius; 0 is square
false if the pointer is down, or true when the pointer status is up
whether the container is the root of the scene
The shape type (used internally).
Whether to update this object when the game is paused.
On a container it covers everything under it: a child steps through a pause on its own opt-in or on one from any container above it, so a pause menu flags itself once and its nested labels follow.
If true, this floating renderable will be rendered by all cameras (e.g. background image layers). If false (default), floating elements are only rendered by the default camera (e.g. UI/HUD elements). Only applies to floating renderables in multi-camera setups.
bottom coordinate of the Rectangle
absolute center of this rectangle on the horizontal axis
absolute center of this rectangle on the vertical axis
the depth of this renderable on the z axis
height of the Rectangle
The left coordinate of the Rectangle.
returns the parent application (or game) to which this renderable is attached to
the parent application or undefined if not attached to any container/app
right coordinate of the Rectangle
since 19.2.0 — use addPostEffect / getPostEffect / removePostEffect instead
The property of the child object that should be used to sort on this container.
"x" / "y" — 2D scroll-order, descending on both axes
(higher pos.z first; tied z, higher pos.x or pos.y first).
Suited to side-scrollers and top-down games."z" — descending pos.z (higher z draws on top). Default for
Camera2d — matches the painter's-algorithm 2D layering model
where pos.z is "layer index"."depth" — Camera3d-only. Ascending squared distance from
the active camera (closest first in the array → far drawn first
→ close drawn on top under Container.draw's reverse-iteration
walk). This is the only correct sort for alpha-blended sprites
under perspective projection, where neither pos.z nor pos.x/y
layering produces correct occlusion (the closer/farther
relationship flips as the camera orbits). Set automatically
when an Application or Stage is constructed with
cameraClass: Camera3d. Has no useful effect under Camera2d
(ortho projection doesn't need camera-distance ordering) and
pays an O(N log N) sort per frame, so don't enable it manually
in 2D-only games.define a tint for this renderable. a (255, 255, 255) r, g, b value will remove the tint effect.
Takes a Color to copy, or a CSS colour string.
It COPIES rather than holds, so a caller that goes on mutating what it
passed does not steer this renderable's tint by accident. What the
getter hands back is always a Color, whichever form went in.
the colour to tint with
top coordinate of the Rectangle
width of the Rectangle
Add a child to the container
if auto-sort is disabled, the object will be appended at the bottom of the list.
Adding a child to the container will automatically remove it from its other container.
Meaning a child can only have one parent. This is important if you add a renderable
to a container then add it to the World container it will move it out of the
original container. Then when the World container reset() method is called the renderable
will not be in any container.
if the given child implements an onActivateEvent method, that method will be called
once the child is added to this container.
Child to be added
Optionalz: number
forces the z index of the child to the specified
value. This depth is scoped to THIS container: it orders the child among
its siblings only, and says nothing about children of another container.
Both drawing and pointer hit-testing resolve a cross-container pair at
the common ancestor instead, so to put a whole subtree in front use
Container#moveToTop on the container rather than a large z on
something inside it. Left out, autoDepth numbers children from 1.
the added child
Add a child to the container at the specified index
(the list won't be sorted after insertion)
Child to be added
The index at which to insert the child
the added child
Add a post-processing shader effect to this renderable.
the effect to add
the added effect
return the angle to the specified target
angle in radians
center the rectangle position around the given coordinates
the x coordinate around which to center this rectangle
the y coordinate around which to center this rectangle
this rectangle
Returns true if the polygon contains the given point.
(Note: it is highly recommended to first do a hit test on the corresponding
bounding rect, as the function can be highly consuming with complex shapes)
x coordinate or a vector point to check
y coordinate
True if the polygon contain the point, otherwise false
Returns true if the polygon contains the given point.
(Note: it is highly recommended to first do a hit test on the corresponding
bounding rect, as the function can be highly consuming with complex shapes)
True if the polygon contain the point, otherwise false
Returns true if the rectangle contains the given rectangle
rectangle to test
True if the rectangle contain the given rectangle, otherwise false
return the distance to the specified target
distance
Check if this rectangle is identical to the specified one.
Other rectangle.
true if equals
flip the renderable on the horizontal axis (around the center of the renderable)
Optionalflip: boolean = true
true to flip this renderable.
Reference to this object for method chaining
flip the renderable on the vertical axis (around the center of the renderable)
Optionalflip: boolean = true
true to flip this renderable.
Reference to this object for method chaining
The forEach() method executes a provided function once per child element.
the callback function is invoked with three arguments:
function to execute on each element
OptionalthisArg: object
value to use as this(i.e reference Object) when executing callback.
Where the panel IS, bob included.
THE hook that makes a floating panel honest. Both bounds paths funnel through this one method, and a child's absolute position is the sum of the chain above it, so adding the offset here reaches the panel's own hit area and every descendant's, at any depth, without any of them knowing a bob exists.
Not currentTransform, which was the obvious guess: that reaches a
renderable's OWN bounds and not its children's, so a bobbing panel's
swallow rectangle would drift off the widgets sitting in it. And not a
write to pos, which would reach everything correctly but silently
overwrite a caller's own write on the very next frame.
Particle overrides this method for the same reason, its
placement not being in its pos chain either.
the absolute position, offset by the bob
Returns the Child at the specified index
The index of the child
the child at the specified index
return the child corresponding to the specified GUID
note : avoid calling this function every frame since
it parses the whole object list each time
child GUID
corresponding child or null
returns the list of children with the specified name
as defined in Tiled (Name field of the Object Properties)
note : avoid calling this function every frame since
it parses the whole object list each time
child name
Array of children
return the child corresponding to the given property and value.
note : avoid calling this function every frame since
it parses the whole object tree each time
Property name
Value of the property
Array of children
// get the first child object called "mainPlayer" in a specific container :
let ent = myContainer.getChildByProp("name", "mainPlayer");
// or query the whole world :
let ent = container.getChildByProp("name", "mainPlayer");
// partial property matches are also allowed by using a RegExp.
// the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
let allCoins = container.getChildByProp("name", /coin/i);
// searching for numbers or other data types :
let zIndex10 = container.getChildByProp("z", 10);
let inViewport = container.getChildByProp("inViewport", true);
returns the list of children with the specified class type
Class type
Array of children
Returns the index of the given Child
The child object
index
returns a list of indices for all triangles defined in this polygon
an array of vertex indices for all triangles forming this polygon.
ProtectedgetReturns the next child within the container or undefined if none
The child object
child
get the renderable alpha channel value
This is the renderable's OWN value. What it finally draws at is this multiplied by every ancestor's — see Renderable#alpha.
current opacity value between 0 and 1
Get post-processing shader effects. When called with a class, returns the first effect matching the given class. When called without arguments, returns the full effects array.
OptionaleffectClass: Function
the effect class to search for
the matching effect, the effects array, or undefined
Returns the instance of the root container (i.e. the current application World container).
root container
The space this renderable's content is drawn IN, as a matrix — the full form of Renderable#getAbsolutePosition, which sums positions up the ancestor chain and therefore cannot represent the rotation, scale or flip accumulated along the way.
Reach for getAbsolutePosition() instead for ordinary positional
work — culling, distance checks, hit tests. It is cheaper and it is what
the engine culls with. Use this when a position is not enough:
inv(A) · B converts
between two frames, which is how ParticleEmitter.referenceSpace
measures particles against a container that is not their parent)The two also frame the question differently, and it shows on a leaf.
getAbsolutePosition() is "where am I"; this is "what space is my
content drawn in". For a Container those coincide, because a
container offsets its children by its own position. For a leaf they
differ by exactly that position, which a leaf applies inside its own
draw(). So with no rotation, scale or flip anywhere, a container's
translation column equals its getAbsolutePosition() while a leaf's
equals its PARENT's.
The walk stops at a floating ancestor, because a floating renderable
draws in screen space: Container#draw resets the transform
outright for those, so the chain genuinely ends there rather than
continuing to the root.
The camera needs no special handling — Camera2d folds its view
transform into the root container's currentTransform, so it is picked
up like any other level.
matrix to write into; nothing is stored on the renderable itself, so callers own the lifetime
out, for chaining
Returns true if contains the specified Child
The child object
Checks if this container is root or if it's attached to the root container.
true if this container is root or if it's attached to the root container
Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
true if the vertices are convex, false if not, null if not computable
Determines whether all coordinates of this rectangle are finite numbers.
false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
Rotate this renderable towards the given target.
the renderable or position to look at
Reference to this object for method chaining
Move the child in the group one step backward (z depth).
Child to be moved
Move the specified child the bottom (z depth).
Child to be moved
Move the specified child to the top(z depth).
Moves the whole subtree: the child's own children keep their depths among themselves and come with it, because depth is resolved per container. This is how one overlapping panel is brought in front of another, for drawing and for pointer hit-testing alike.
Child to be moved
Move the child in the group one step forward (z depth).
Child to be moved
Consume a click on the panel itself, unless told not to.
Returning false is how UIBaseElement consumes. A child is
asked before the container holding it, so this only ever sees a click
that missed every one of them, which for a dialog means a click on its
own background and should go no further.
false while UIPanel#blocking
Legacy collision callback — fires every frame this renderable body is overlapping another body. Kept for backward compatibility with code written against pre-19.5 melonJS; semantics are unchanged from the 19.4 contract.
NOTE — onCollision is NOT equivalent to Renderable.onCollisionActive.
The two handlers exist side by side and have intentionally different
contracts:
onCollision (legacy) |
onCollisionActive (modern) |
|
|---|---|---|
| Cadence for dynamic-dynamic pairs | 2× per frame per side | 1× per frame per side |
response.a semantics |
Fixed per pair (first body in detector call) | Always the receiver (response.a === this) |
response.b semantics |
Fixed per pair | Always the partner (response.b === other) |
response.normal / response.depth |
✗ | ✓ — normal.y < -0.7 = "push me up" |
return false to skip push-out |
✓ (honored by SAT) | ✗ — use bodyDef.isSensor or setSensor instead |
If you're writing new code, prefer onCollisionActive. Keep
onCollision only when its every-frame, return-false, fixed-a/b
semantics are what you want.
the SAT response object; the legacy handler receives this, not the adapter's CollisionResponse, which is why normal and depth are absent from the table above
the other renderable touching this one (a reference to response.a or response.b)
true if the object should respond to the collision (its position and velocity will be corrected); the return value is only honored by the builtin SAT adapter.
function called when the object is pressed and held
to be extended
function called when the pointer is moved over the object
Optional_event: Pointer
the event object
function called when the pointer is leaving the object area.
Fires when the pointer leaves the element's bounds, and also when it is still inside them but something drawn above has consumed the move, since the pointer is then over that instead.
Unlike UIBaseElement#onOver this one cannot consume the event, on purpose: an element that suppressed its own leave would stay in its hover state after the pointer had gone.
Optional_event: Pointer
the event object
Consume a hover on the panel itself, unless told not to.
Without this a widget UNDER a dialog keeps lighting up as the pointer crosses the panel covering it.
false while UIPanel#blocking
Consume the release that follows a click on the panel, unless told not to.
The three handlers consume independently. Taking the press and leaving the release is half a block: the pointer-up still reaches whatever is under the dialog, so a button there completes an interaction it never began.
false while UIPanel#blocking
check if this rectangle is intersecting with the specified one
Other rectangle.
true if overlaps
restore the rendering context after drawing (automatically called by melonJS).
a renderer object
Prepare the rendering context before drawing (automatically called by melonJS). This will apply any defined transforms, anchor point, tint or blend mode and translate the context accordingly to this renderable position.
a renderer object
Computes the calculated collision polygon.
This must be called if the points array, angle, or offset is modified manually.
Reference to this object for method chaining
Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed.
if the given child implements an onDeactivateEvent() method, that method will be called once the child is removed from this container.
Child to be removed
Optionalkeepalive: boolean
true to prevent calling child.destroy()
Removes (and optionally destroys) a child from the container.
(removal is immediate and unconditional)
Never use keepalive=true with objects from pool. Doing so will create a memory leak.
Child to be removed
Optionalkeepalive: boolean
True to prevent calling child.destroy()
Remove a specific post-processing shader effect.
the effect to remove
reset the container, removing all children, and resetting transforms.
resize the rectangle
new width of the rectangle
new height of the rectangle
this rectangle
Rotate this renderable by the specified angle (in radians). When called with just an angle, rotates around the Z axis (2D rotation). When called with an angle and a Vector3d axis, rotates around that axis in 3D.
The angle to rotate (in radians)
Optionalv: Vector3d
the axis to rotate around (defaults to Z axis for 2D)
Reference to this object for method chaining
scale the renderable around his anchor point. Scaling actually applies changes to the currentTransform member which is used by the renderer to scale the object when rendering. It does not scale the object itself. For example if the renderable is an image, the image.width and image.height properties are unaltered but the currentTransform member will be changed.
a number representing the abscissa of the scaling vector.
Optionaly: number = x
a number representing the ordinate of the scaling vector.
Optionalz: number = 1
a number representing the depth of the scaling vector.
Reference to this object for method chaining
Automatically set the specified property of all childs to the given value
This ASSIGNS to the children — after it, their own property carries the value. To fade a subtree without touching what the children are, set Renderable#alpha on the container instead: opacity cascades at draw time and leaves every child's own value alone.
property name
property value; whatever the named property holds, so a flag is a boolean and a colour is a string, not only an object
Optionalrecursive: boolean
recursively apply the value to child containers if true
set the renderable alpha channel value
opacity value between 0.0 and 1.0
Move this renderable, optionally in three dimensions.
pos holds an ObservableVector3d, but the geometry this class
inherits from declares it as a 2D vector, so from TypeScript
pos.set(x, y) takes two arguments and silently writes a zero z.
Anything with a depth then drops to the near plane. Reaching past that
previously meant a double cast or assigning pos.x, pos.y and
depth by hand, which is why that pattern is written out dozens of
times across the examples.
Omitting z leaves the depth exactly as it was, rather than
zeroing it. That is the whole difference from pos.set(x, y), and it
is what makes this safe to call on a 2D sprite that happens to sit at
a depth, or on a Camera2d, without having to know whether it does.
the new x position
the new y position
Optionalz: number
the new depth; left untouched when omitted
this renderable, for chaining
set new value to the Polygon
position of the Polygon
position of the Polygon
array of vector or vertices defining the Polygon
this instance for object chaining
Set new dimensions for the rectangle.
The new width of the rectangle.
The new height of the rectangle.
Tint this renderable, chainably.
Exactly Renderable#tint's own setter, returning the renderable
so it can be chained with the other set* methods. It exists because
tint is a live Color, so reaching for it means choosing
between setColor (0 to 255), setFloat (0 to 1), parseCSS,
setHSL and setLinear — and picking the wrong one is silent, it just
renders the wrong colour.
Deliberately sRGB only. A LINEAR value, which in practice means a glTF
baseColorFactor or emissiveFactor, stays an explicit
tint.setLinear(...) so the conversion is never silent; for a mesh
built from an asset, pass Mesh#baseColorFactor as a setting and
the loader's value is applied for you.
a Color to copy, or a CSS colour string
this renderable, for chaining
set the vertices defining this Polygon
array of vector or vertices defining the Polygon
this instance for object chaining
Manually trigger the sort of all the childs in the container
Optionalrecursive: boolean
recursively sort all containers if true
Synchronous variant of Container#sort. Sorts immediately
— no defer — using the current _comparator. Intended for
per-frame callers that need the order to be valid for the very
next render (e.g. Camera3d refreshing the "depth" sort after
the camera has moved, where waiting for the deferred sort tick
would render a stale frame).
Optionalrecursive: boolean
recursively sort sub-containers
Swaps the position (z-index) of 2 children
Child to be added
Child to be added
apply an isometric projection to this shape
Reference to this object for method chaining
Returns a polygon whose edges are the same as this box.
a new Polygon that represents this rectangle.
Translate the renderable by the specified offset.
Reference to this object for method chaining
Advance the bob.
time since the last frame, in milliseconds
whether the panel needs redrawing
Resize this panel's bounds, and refresh its children's.
Container does those two jobs in ONE loop, both gated on
enableChildBoundsUpdate, and a panel wants exactly one of them. The
flag is off here so that a label overhanging the edge cannot grow the
rectangle a blocking panel swallows clicks inside, and turning it off
took the other job with it: a child's bounds are absolute, worked out
once through getAbsolutePosition() and then cached, so moving the
panel left every child's HIT AREA behind at the old place while the
whole panel drew at the new one. A dialog slid or snapped into position
after it was built had buttons that only answered where they used to
be.
This costs nothing per frame: pos calls updateBounds when it is
written, so the walk happens when the panel actually moves.
update in world absolute coordinates
this panel's bounds
A rectangular surface with a background, an optional border and children.
The thing every menu, dialog and HUD frame starts by writing: a rounded rectangle, a fill, an outline, and some labels on top. One example in this repository had three of them, each repeating the same half dozen renderer calls, and each repeating the same correction for the way
setColorfolds the global alpha in. That correction is the reason this is a widget rather than a snippet: it is easy to leave out, and leaving it out does not fail, it just renders a panel at the wrong opacity.It is a UIBaseElement, so it is a container that carries pointer events, and children added to it are drawn over its background and are asked about a click before it is.
It is floating, as every UI element is, and where it lands in the paint order is the depth it is added at. In a world sorted on
"depth", which is everyCamera3dscene, that depth is read the other way round from the 2D habit: a floating child is ranked by|pos.z|there and the SMALLER magnitude draws on top, so a panel added at 9000 to sit above everything sits behind everything instead, and a dialog there wants a small depth, 0 or 1.Example