NapeSystem
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.
If set to true
, physics simulation is paused.
Bodies maintain their state but don't move or collide.
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 |
Adds a physics space to be updated by the system.
Name | Type | Description |
---|---|---|
space |
nape.space.Space | Space to add for automatic stepping |
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 |
Creates the Nape physics system. Initializes the default space with zero gravity.
Private Members
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 |
Triggered right before applying nape bodies to visuals. Visual positions are about to be updated from physics.
Triggered right after applying nape bodies to visuals. Visual positions have been synchronized with physics.
Updates all physics spaces by stepping their simulations.
Name | Type | Description |
---|---|---|
delta |
Float | Time step in seconds |
Steps a single physics space forward in time.
Name | Type | Description |
---|---|---|
space |
nape.space.Space | Space to update |
delta |
Float | Time step in seconds |
Main update cycle for physics simulation.
Order of operations:
- Validate all physics items (remove orphaned bodies)
- Process creation/destruction queues
- Step physics simulation
- Synchronize visual positions with physics
Name | Type | Description |
---|---|---|
delta |
Float | Time elapsed since last update |
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) |
Processes the queue of destroyed physics items. Removes them from the active items list.
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 |