VisualArcadePhysics
Component that adds Arcade physics functionality to a Visual.
This class bridges Ceramic's visual system with the Arcade physics engine,
allowing any Visual to have physics properties like velocity, gravity, and
collision detection. It's automatically created when accessing a visual's
arcade
property.
The component manages:
- Physics body creation and synchronization
- Collision and overlap event dispatching
- World bounds detection
- Automatic cleanup on destruction
Usage example:
// Enable physics on a visual
var player = new Quad();
player.arcade.initBody(0, 0, 32, 32, 0);
player.arcade.body.velocity.y = -300; // Jump!
// Listen for collisions
player.arcade.onCollide(this, (v1, v2) -> {
trace("Collision detected!");
});
Static Members
Retrieves the VisualArcadePhysics component associated with a physics body.
Useful when you have a body reference from a collision callback and need to access the visual or arcade component.
Name | Type | Description |
---|---|---|
body |
arcade.Body | The physics body to look up |
Returns | Description |
---|---|
VisualArcadePhysics | The VisualArcadePhysics component, or null if the body doesn't belong to a visual |
Instance Members
The Visual that owns this physics component. Set automatically when the component is created.
The Arcade physics body attached to the visual.
This provides access to all physics properties:
- velocity, acceleration, drag
- immovable, mass, bounce
- collision flags (checkCollisionUp/Down/Left/Right)
Created by calling initBody().
The physics world this body belongs to.
If not set explicitly, uses the default world from ArcadeSystem. Different worlds can have different gravity, bounds, and collision groups.
Horizontal offset of the physics body from the visual's position. Useful when the collision box should be smaller or shifted from the visual.
Vertical offset of the physics body from the visual's position. Useful when the collision box should be smaller or shifted from the visual.
Initializes the physics body with the specified dimensions.
Must be called before the body can be used in physics simulation. The body's position will be synchronized with the visual each frame.
Name | Type | Description |
---|---|---|
x |
Float | Initial X position of the body |
y |
Float | Initial Y position of the body |
width |
Float | Width of the collision box |
height |
Float | Height of the collision box |
rotation |
Float | Initial rotation in degrees |
Destroys this physics component and its body.
Automatically called when the visual is destroyed. Removes the component from the physics system and cleans up references.
Creates a new VisualArcadePhysics component.
Automatically registers with the ArcadeSystem for updates. Usually created automatically when accessing visual.arcade.
Private Members
Dispatched when this visual's body collides with another body.
This event fires for any collision, regardless of whether the other body belongs to a Visual or is a standalone physics body.
Name | Type | Description |
---|---|---|
visual |
Visual | The Visual that owns this physics component |
body |
arcade.Body | The other body involved in the collision |
Dispatched when this visual's body overlaps with another body.
Overlaps occur when bodies intersect but don't push each other apart. Useful for triggers, collectibles, and detection zones.
Name | Type | Description |
---|---|---|
visual |
Visual | The Visual that owns this physics component |
body |
arcade.Body | The other body involved in the overlap |
Dispatched when this visual collides with another visual.
This is a convenience event that only fires when both bodies belong to Visual objects, making it easier to work with visual-to-visual collisions.
Name | Type | Description |
---|---|---|
visual1 |
Visual | This visual |
visual2 |
Visual | The other visual involved in the collision |
Dispatched when this visual overlaps with another visual.
This is a convenience event that only fires when both bodies belong to Visual objects, making it easier to work with visual-to-visual overlaps.
Name | Type | Description |
---|---|---|
visual1 |
Visual | This visual |
visual2 |
Visual | The other visual involved in the overlap |
Dispatched when this visual's body collides with the world boundaries.
World bounds define the edges of the physics simulation area. Bodies can be configured to collide with these bounds using body.collideWorldBounds = true.
Name | Type | Description |
---|---|---|
visual |
Visual | The Visual that hit the world bounds |
up |
Bool | True if hit the top boundary |
down |
Bool | True if hit the bottom boundary |
left |
Bool | True if hit the left boundary |
right |
Bool | True if hit the right boundary |
Internal: Sets up collision event handler when listeners are added.
Internal collision event handler that dispatches appropriate events.
Name | Type |
---|---|
body1 |
arcade.Body |
body2 |
arcade.Body |
Internal overlap event handler that dispatches appropriate events.
Name | Type |
---|---|
body1 |
arcade.Body |
body2 |
arcade.Body |
Internal world bounds collision handler that dispatches the worldBounds event.
Name | Type |
---|---|
body1 |
arcade.Body |
up |
Bool |
down |
Bool |
left |
Bool |
right |
Bool |
Metadata
Name | Parameters |
---|---|
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |