phaser - v3.90.0
    Preparing search index...

    Provides methods used for getting and setting the mask of a Game Object.

    interface Mask {
        mask: BitmapMask | GeometryMask;
        clearMask(destroyMask?: boolean): this;
        createBitmapMask<G extends GameObject, T extends DynamicTexture>(
            maskObject?: GameObject | DynamicTexture,
            x?: number,
            y?: number,
            texture?: string | Textures.Texture,
            frame?: string | number | Frame,
        ): BitmapMask;
        createGeometryMask<G extends GameObjects.Graphics, S extends Shape>(
            graphics?: GameObjects.Graphics | Shape,
        ): GeometryMask;
        setMask(mask: BitmapMask | GeometryMask): this;
    }

    Implemented by

    Index

    Properties

    The Mask this Game Object is using during render.

    Methods

    • Clears the mask that this Game Object was using.

      Parameters

      • OptionaldestroyMask: boolean

        Destroy the mask before clearing it? Default false.

      Returns this

    • Creates and returns a Bitmap Mask. This mask can be used by any Game Object, including this one, or a Dynamic Texture.

      Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas.

      To create the mask you need to pass in a reference to a renderable Game Object. A renderable Game Object is one that uses a texture to render with, such as an Image, Sprite, Render Texture or BitmapText.

      If you do not provide a renderable object, and this Game Object has a texture, it will use itself as the object. This means you can call this method to create a Bitmap Mask from any renderable texture-based Game Object.

      Type Parameters

      Parameters

      • OptionalmaskObject: GameObject | DynamicTexture

        The Game Object or Dynamic Texture that will be used as the mask. If null it will generate an Image Game Object using the rest of the arguments.

      • Optionalx: number

        If creating a Game Object, the horizontal position in the world.

      • Optionaly: number

        If creating a Game Object, the vertical position in the world.

      • Optionaltexture: string | Textures.Texture

        If creating a Game Object, the key, or instance of the Texture it will use to render with, as stored in the Texture Manager.

      • Optionalframe: string | number | Frame

        If creating a Game Object, an optional frame from the Texture this Game Object is rendering with.

      Returns BitmapMask

    • Creates and returns a Geometry Mask. This mask can be used by any Game Object, including this one.

      To create the mask you need to pass in a reference to a Graphics Game Object.

      If you do not provide a graphics object, and this Game Object is an instance of a Graphics object, then it will use itself to create the mask.

      This means you can call this method to create a Geometry Mask from any Graphics Game Object.

      Type Parameters

      Parameters

      • Optionalgraphics: GameObjects.Graphics | Shape

        A Graphics Game Object, or any kind of Shape Game Object. The geometry within it will be used as the mask.

      Returns GeometryMask

    • Sets the mask that this Game Object will use to render with.

      The mask must have been previously created and can be either a GeometryMask or a BitmapMask. Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas.

      If a mask is already set on this Game Object it will be immediately replaced.

      Masks are positioned in global space and are not relative to the Game Object to which they are applied. The reason for this is that multiple Game Objects can all share the same mask.

      Masks have no impact on physics or input detection. They are purely a rendering component that allows you to limit what is visible during the render pass.

      Parameters

      Returns this