PokéRogue
    Preparing search index...

    A wrapper around a Tile that provides access to a corresponding Matter body. A tile can only have one Matter body associated with it. You can either pass in an existing Matter body for the tile or allow the constructor to create the corresponding body for you. If the Tile has a collision group (defined in Tiled), those shapes will be used to create the body. If not, the tile's rectangle bounding box will be used.

    The corresponding body will be accessible on the Tile itself via Tile.physics.matterBody.

    Note: not all Tiled collision shapes are supported. See Phaser.Physics.Matter.TileBody#setFromTileCollision for more information.

    Hierarchy (View Summary)

    Implements

    Index
    centerOfMass: Vector2

    The body's center of mass.

    Calling this creates a new Vector2 each time to avoid mutation.

    If you only need to read the value and won't change it, you can get it from GameObject.body.centerOfMass.

    tile: Tile

    The tile object the body is associated with.

    world: World

    The Matter world the body exists within.

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

      this.

    • Destroys this TileBody, removing the current body from the Matter world, clearing the reference on the tile, and removing all event listeners.undefined

      Returns TileBody

      This TileBody object.

    • Calls each of the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • ...args: any[]

        Additional arguments that will be passed to the event handler.

      Returns boolean

      true if the event had listeners, else false.

    • Return an array listing the events for which the emitter has registered listeners.undefined

      Returns (string | symbol)[]

      undefined

    • Is the body belonging to this Game Object a sensor or not?undefined

      Returns boolean

      true if the body is a sensor, otherwise false.

    • Returns true if the body is static, otherwise false for a dynamic body.undefined

      Returns boolean

      true if the body is static, otherwise false.

    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns number

      The number of listeners.

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

      The registered listeners.

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

      this.

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

      this.

    • Add a one-time listener for a given event. The listener is automatically removed the first time the event is emitted, so it will never be called more than once.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

      this.

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: string | symbol

        The event name.

      Returns this

      this.

    • Removes the current body from the TileBody and from the Matter world.undefined

      Returns TileBody

      This TileBody object.

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

      this.

    • Wakes this physics body if it is currently asleep, returning it to active simulation. Once awake, the body will resume participating in collisions and physics updates.undefined

      Returns this

      This Game Object instance.

    • Sets the current body to the given body. This will remove the previous body, if one already exists.

      Parameters

      • body: BodyType

        The new Matter body to use.

      • OptionaladdToWorld: boolean

        Whether or not to add the body to the Matter world. Default true.

      Returns TileBody

      This TileBody object.

    • Sets the restitution (bounciness) of this Game Object's Matter.js physics body. This controls how much of the body's kinetic energy is preserved after a collision.

      Parameters

      • value: number

        A Number that defines the restitution (elasticity) of the body. The value is always positive and is in the range (0, 1). A value of 0 means collisions may be perfectly inelastic and no bouncing may occur. A value of 0.8 means the body may bounce back with approximately 80% of its kinetic energy. Note that collision response is based on pairs of bodies, and that restitution values are combined with the following formula: Math.max(bodyA.restitution, bodyB.restitution)

      Returns this

      This Game Object instance.

    • Sets the collision mask for this Game Object's Matter Body. Two Matter Bodies with different collision groups will only collide if each one includes the other's category in its mask based on a bitwise AND, i.e. (categoryA & maskB) !== 0 and (categoryB & maskA) !== 0 are both true.

      Parameters

      • categories: number | number[]

        A unique category bitfield, or an array of them.

      Returns this

      This Game Object instance.

    • Sets the collision category of this Game Object's Matter Body. This number must be a power of two between 2^0 (= 1) and 2^31. Two bodies with different collision groups (see #setCollisionGroup) will only collide if their collision categories are included in their collision masks (see #setCollidesWith).

      Parameters

      • value: number

        Unique category bitfield.

      Returns this

      This Game Object instance.

    • Sets the collision group of this Game Object's Matter Body. If this is zero or two Matter Bodies have different values, they will collide according to the usual rules (see #setCollisionCategory and #setCollidesWith). If two Matter Bodies have the same positive value, they will always collide; if they have the same negative value, they will never collide.

      Parameters

      • value: number

        Unique group index.

      Returns this

      This Game Object instance.

    • Sets the density of the body.

      Parameters

      • value: number

        The new density of the body.

      Returns this

      This Game Object instance.

    • Sets new friction values for this Game Object's Matter Body.

      Parameters

      • value: number

        The new friction of the body, between 0 and 1, where 0 allows the Body to slide indefinitely, while 1 allows it to stop almost immediately after a force is applied.

      • Optionalair: number

        If provided, the new air resistance of the Body. The higher the value, the faster the Body will slow as it moves through space. 0 means the body has no air resistance.

      • Optionalfstatic: number

        If provided, the new static friction of the Body. The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary. 0 means the body will never "stick" when it is nearly stationary.

      Returns this

      This Game Object instance.

    • Sets a new air resistance for this Game Object's Matter Body. A value of 0 means the Body will never slow as it moves through space. The higher the value, the faster a Body slows when moving through space.

      Parameters

      • value: number

        The new air resistance for the Body.

      Returns this

      This Game Object instance.

    • Sets a new static friction for this Game Object's Matter Body. A value of 0 means the Body will never "stick" when it is nearly stationary. The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary.

      Parameters

      • value: number

        The new static friction for the Body.

      Returns this

      This Game Object instance.

    • Sets the current body from the collision group associated with the Tile. This is typically set up in Tiled's collision editor.

      Note: Matter doesn't support all shapes from Tiled. Rectangles and polygons are directly supported. Ellipses are converted into circle bodies. Polylines are treated as if they are closed polygons. If a tile has multiple shapes, a multi-part body will be created. Concave shapes are supported if poly-decomp library is included. Decomposition is not guaranteed to work for complex shapes (e.g. holes), so it's often best to manually decompose a concave polygon into multiple convex polygons yourself.

      Parameters

      • Optionaloptions: MatterBodyTileOptions

        Options to be used when creating the Matter body. See MatterJS.Body for a list of what Matter accepts.

      Returns TileBody

      This TileBody object.

    • Sets the current body to a rectangle that matches the bounds of the tile.

      Parameters

      • Optionaloptions: MatterBodyTileOptions

        Options to be used when creating the Matter body. See MatterJS.Body for a list of what Matter accepts.

      Returns TileBody

      This TileBody object.

    • Sets whether this Game Object's Matter.js body should ignore world gravity. When set to true, the body will not be influenced by the global gravity defined in the Matter.js world configuration, allowing it to float freely regardless of the world's gravity settings. This can be changed at any time during gameplay to dynamically enable or disable gravity on the body.

      Parameters

      • value: boolean

        Set to true to ignore the effect of world gravity, or false to not ignore it.

      Returns this

      This Game Object instance.

    • Sets the mass of the Game Object's Matter Body.

      Parameters

      • value: number

        The new mass of the body.

      Returns this

      This Game Object instance.

    • Sets a callback to be invoked when this Game Object's Matter Body begins colliding with another body. The callback is sent a Phaser.Types.Physics.Matter.MatterCollisionData object.

      This does not change the bodies collision category, group or filter. Those must be set in addition to the callback.

      Parameters

      • callback: Function

        The callback to invoke when this body starts colliding with another.

      Returns this

      This Game Object instance.

    • Sets a callback to be invoked each step while this Game Object's Matter Body is actively colliding with another body. The callback is sent a Phaser.Types.Physics.Matter.MatterCollisionData object.

      This does not change the bodies collision category, group or filter. Those must be set in addition to the callback.

      Parameters

      • callback: Function

        The callback to invoke for the duration of this body colliding with another.

      Returns this

      This Game Object instance.

    • Sets a callback to be invoked when this Game Object's Matter Body stops colliding with another body. The callback is sent a Phaser.Types.Physics.Matter.MatterCollisionData object.

      This does not change the bodies collision category, group or filter. Those must be set in addition to the callback.

      Parameters

      • callback: Function

        The callback to invoke when this body stops colliding with another.

      Returns this

      This Game Object instance.

    • Sets a callback to be invoked when this Game Object's Matter Body collides with a specific body or bodies. The callback is sent a reference to the other body, along with a Phaser.Types.Physics.Matter.MatterCollisionData object.

      This does not change the bodies collision category, group or filter. Those must be set in addition to the callback.

      Parameters

      • body: Body | Body[]

        The body, or an array of bodies, to test for collisions with.

      • callback: Function

        The callback to invoke when this body collides with the given body or bodies.

      Returns this

      This Game Object instance.

    • Set the body belonging to this Game Object to be a sensor. Sensors trigger collision events, but don't physically react to or push colliding bodies.

      Parameters

      • value: boolean

        true to set the body as a sensor, or false to disable it.

      Returns this

      This Game Object instance.

    • Enables or disables the Sleep End event for this body.

      Parameters

      • value: boolean

        true to enable the SLEEP_END event for this body, or false to disable it.

      Returns this

      This Game Object instance.

    • Enable sleep and wake events for this body.

      By default when a body goes to sleep, or wakes up, it will not emit any events.

      The events are emitted by the Matter World instance and can be listened to via the SLEEP_START and SLEEP_END events.

      Parameters

      • start: boolean

        true if you want the sleep start event to be emitted for this body.

      • end: boolean

        true if you want the sleep end event to be emitted for this body.

      Returns this

      This Game Object instance.

    • Enables or disables the Sleep Start event for this body.

      Parameters

      • value: boolean

        true to enable the SLEEP_START event for this body, or false to disable it.

      Returns this

      This Game Object instance.

    • Sets the number of updates in which this body must have near-zero velocity before it is set as sleeping (if sleeping is enabled by the engine).

      Parameters

      • Optionalvalue: number

        The number of consecutive updates with near-zero velocity required before the body is put to sleep. Default 60.

      Returns this

      This Game Object instance.

    • Changes the physics body to be either static true or dynamic false.

      Parameters

      • value: boolean

        true to set the body as being static, or false to make it dynamic.

      Returns this

      This Game Object instance.

    • Immediately puts this physics body to sleep, removing it from active simulation. A sleeping body will not move, generate collisions, or consume CPU until it is woken. It can be woken manually via setAwake, or automatically when struck by another body.undefined

      Returns this

      This Game Object instance.

    • Removes all listeners from this EventEmitter. This method is called automatically by the Scene Systems when the parent Scene shuts down, ensuring that all event bindings are cleared and no stale references remain.

      Returns void