NapeSystem

EntitySystemceramic.NapeSystem (Class)

Central system managing Nape physics simulation in Ceramic.

Handles:

  • Multiple physics spaces (worlds)
  • Automatic synchronization between Nape bodies and Ceramic visuals
  • Physics stepping and timing
  • Body lifecycle management

The system automatically updates visual positions and rotations based on their associated physics bodies after each physics step.

// Access the default physics space
var space = app.nape.space;
space.gravity.setxy(0, 600); // Set gravity

// Create additional spaces
var customSpace = app.nape.createSpace();
customSpace.gravity.setxy(0, 300);

// Pause all physics
app.nape.paused = true;

Instance Members

All active physics body items being managed. Each item links a Nape body to a Ceramic visual.


All physics spaces (worlds) used with Nape physics. Multiple spaces allow for separate physics simulations.


Default space for Nape physics. Bodies are added to this space unless specified otherwise. Has zero gravity by default.


nape
paused: Bool

If set to true, physics simulation is paused. Bodies maintain their state but don't move or collide.


nape
createSpace(?autoAdd: Bool = true): nape.space.Space

Creates a new physics space (world).

Each space is an independent physics simulation with its own gravity, bodies, and constraints.

Name Type Default Description
autoAdd Bool true If true, automatically adds the space to be updated
Returns Description
nape.space.Space New physics space with zero gravity

nape
addSpace(space: nape.space.Space): Void

Adds a physics space to be updated by the system.

Name Type Description
space nape.space.Space Space to add for automatic stepping

nape
removeSpace(space: nape.space.Space): Void

Removes a physics space from automatic updates.

The space itself is not destroyed, just removed from the update list.

Name Type Description
space nape.space.Space Space to stop updating

nape
new(): Void

Creates the Nape physics system. Initializes the default space with zero gravity.

Private Members

nape
emitUpdateSpaces(delta: Float): Void

Triggered right before updating/stepping nape spaces. Use this to apply forces or modify physics state before simulation.

Name Type Description
delta Float Time step in seconds

nape
emitBeginUpdateVisuals(): Void

Triggered right before applying nape bodies to visuals. Visual positions are about to be updated from physics.


nape
emitEndUpdateVisuals(): Void

Triggered right after applying nape bodies to visuals. Visual positions have been synchronized with physics.


nape
updateSpaces(delta: Float): Void

Updates all physics spaces by stepping their simulations.

Name Type Description
delta Float Time step in seconds

nape
updateSpace(space: nape.space.Space, delta: Float): Void

Steps a single physics space forward in time.

Name Type Description
space nape.space.Space Space to update
delta Float Time step in seconds

nape
earlyUpdate(delta: Float): Void

Main update cycle for physics simulation.

Order of operations:

  1. Validate all physics items (remove orphaned bodies)
  2. Process creation/destruction queues
  3. Step physics simulation
  4. Synchronize visual positions with physics
Name Type Description
delta Float Time elapsed since last update

nape
updateVisuals(delta: Float): Void

Synchronizes visual positions with physics body positions.

Takes into account:

  • Visual anchor points
  • Scale transformations
  • Rotation (if allowed by body)

Physics bodies are positioned at their center, while visuals can have arbitrary anchor points, requiring transformation.

Name Type Description
delta Float Time step (unused but passed for consistency)

nape
flushDestroyedItems(): Void

Processes the queue of destroyed physics items. Removes them from the active items list.


nape
flushCreatedItems(): Void

Processes the queue of newly created physics items. Adds them to the active items list.

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:allow ceramic.App