PokéRogue
    Preparing search index...

    Interface Collision

    Provides methods used for setting the collision category and mask of an Arcade Physics Body.

    Collision categories and masks allow you to control which bodies interact with each other. Each body has a collision category (its "identity") and a collision mask (the set of categories it will collide with). Two bodies will only collide if each body's category is present in the other body's mask. By default, all bodies belong to category 1 and collide with all categories.

    interface Collision {
        addCollidesWith(category: number): this;
        removeCollidesWith(category: number): this;
        resetCollisionCategory(): this;
        setCollidesWith(categories: number | number[]): this;
        setCollisionCategory(category: number): this;
        willCollideWith(category: number): boolean;
    }

    Implemented by

    Index
    • Adds the given Collision Category to the list of those that this Arcade Physics Body will collide with.

      Parameters

      • category: number

        The collision category to add to this body's collision mask.

      Returns this

      This Game Object.

    • Removes the given Collision Category from the list of those that this Arcade Physics Body will collide with.

      Parameters

      • category: number

        The collision category to remove from this body's collision mask.

      Returns this

      This Game Object.

    • Resets the Collision Category and Mask back to the defaults, which means the body will belong to category 1 and will collide with all other categories.undefined

      Returns this

      This Game Object.

    • Sets all of the Collision Categories that this Arcade Physics Body will collide with. You can either pass a single category value, or an array of them.

      Calling this method will reset all of the collision categories, so only those passed to this method are enabled.

      If you wish to add a new category to the existing mask, call the addCollidesWith method.

      If you wish to reset the collision category and mask, call the resetCollisionCategory method.

      Parameters

      • categories: number | number[]

        The collision category to collide with, or an array of them.

      Returns this

      This Game Object.

    • Sets the Collision Category that this Arcade Physics Body will use in order to determine what it can collide with.

      It can only have one single category assigned to it.

      If you wish to reset the collision category and mask, call the resetCollisionCategory method.

      Parameters

      • category: number

        The collision category to assign to this body. Typically a power of 2, such as 1, 2, 4, 8, and so on.

      Returns this

      This Game Object.

    • Checks to see if the given Collision Category will collide with this Arcade Physics object or not.

      Parameters

      • category: number

        Collision category value to test.

      Returns boolean

      true if the given category will collide with this object, otherwise false.