phaser - v4.0.0-rc.4
    Preparing search index...

    The Canvas Renderer is responsible for managing 2D canvas rendering contexts, including the one used by the Games canvas. It tracks the internal state of a given context and can renderer textured Game Objects to it, taking into account alpha, blending, and scaling.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    antialias: boolean

    Should the Canvas use Image Smoothing or not when drawing Sprites?

    blendModes: any[]

    The blend modes supported by the Canvas Renderer.

    This object maps the Phaser.BlendModes to canvas compositing operations.

    config: object

    The local configuration settings of the CanvasRenderer.

    currentContext: CanvasRenderingContext2D

    The canvas context currently used by the CanvasRenderer for all rendering operations.

    drawCount: number

    The total number of Game Objects which were rendered in a frame.

    game: Game

    The Phaser Game instance that owns this renderer.

    gameCanvas: HTMLCanvasElement

    The canvas element which the Game uses.

    gameContext: CanvasRenderingContext2D

    The canvas context used to render all Cameras in all Scenes during the game loop.

    height: number

    The height of the canvas being rendered to.

    isBooted: boolean

    Has this renderer fully booted yet?

    snapshotState: SnapshotState

    Details about the currently scheduled snapshot.

    If a non-null callback is set in this object, a snapshot of the canvas will be taken after the current frame is fully rendered.

    type: number

    A constant which allows the renderer to be easily identified as a Canvas Renderer.

    width: number

    The width of the canvas being rendered to.

    Methods

    • 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

    • Takes a Sprite Game Object, or any object that extends it, and draws it to the current context.

      Parameters

      • sprite: GameObject

        The texture based Game Object to draw.

      • frame: Frame

        The frame to draw, doesn't have to be that owned by the Game Object.

      • camera: Cameras.Scene2D.Camera

        The Camera to use for the rendering transform.

      • OptionalparentTransformMatrix: TransformMatrix

        The transform matrix of the parent container, if set.

      Returns void

    • 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

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

      Parameters

      • event: string | symbol

        The event name.

      Returns number

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

    • 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

    • 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

    • Add a one-time 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

    • The event handler that manages the resize event dispatched by the Scale Manager.

      Parameters

      • gameSize: Structs.Size

        The default Game Size object. This is the un-modified game dimensions.

      • baseSize: Structs.Size

        The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this.

      Returns void

    • Restores the game context's global settings and takes a snapshot if one is scheduled.

      The post-render step happens after all Cameras in all Scenes have been rendered.

      Returns void

    • 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

    • The core render step for a Scene Camera.

      Iterates through the given array of Game Objects and renders them with the given Camera.

      This is called by the CameraManager.render method. The Camera Manager instance belongs to a Scene, and is invoked by the Scene Systems.render method.

      This method is not called if Camera.visible is false, or Camera.alpha is zero.

      Parameters

      • scene: Scene

        The Scene to render.

      • children: GameObject[]

        An array of filtered Game Objects that can be rendered by the given Camera.

      • camera: Cameras.Scene2D.Camera

        The Scene Camera to render with.

      Returns void

    • Resets the transformation matrix of the current context to the identity matrix, thus resetting any transformation.

      Returns void

    • Resize the main game canvas.

      Parameters

      • Optionalwidth: number

        The new width of the renderer.

      • Optionalheight: number

        The new height of the renderer.

      Returns void

    • Sets the global alpha of the current context.

      Parameters

      • alpha: number

        The new alpha to use, where 0 is fully transparent and 1 is fully opaque.

      Returns this

    • Sets the blend mode (compositing operation) of the current context.

      Parameters

      • blendMode: string

        The new blend mode which should be used.

      Returns this

    • Changes the Canvas Rendering Context that all draw operations are performed against.

      Parameters

      • Optionalctx: CanvasRenderingContext2D

        The new Canvas Rendering Context to draw everything to. Leave empty to reset to the Game Canvas.

      Returns this

    • Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered.

      To capture a specific area see the snapshotArea method. To capture a specific pixel, see snapshotPixel.

      Only one snapshot can be active per frame. If you have already called snapshotPixel, for example, then calling this method will override it.

      Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

      Parameters

      • callback: SnapshotCallback

        The Function to invoke after the snapshot image is created.

      • Optionaltype: string

        The format of the image to create, usually image/png or image/jpeg. Default 'image/png'.

      • OptionalencoderOptions: number

        The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg. Default 0.92.

      Returns this

    • Schedules a snapshot of the given area of the game viewport to be taken after the current frame is rendered.

      To capture the whole game viewport see the snapshot method. To capture a specific pixel, see snapshotPixel.

      Only one snapshot can be active per frame. If you have already called snapshotPixel, for example, then calling this method will override it.

      Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

      Parameters

      • x: number

        The x coordinate to grab from.

      • y: number

        The y coordinate to grab from.

      • width: number

        The width of the area to grab.

      • height: number

        The height of the area to grab.

      • callback: SnapshotCallback

        The Function to invoke after the snapshot image is created.

      • Optionaltype: string

        The format of the image to create, usually image/png or image/jpeg. Default 'image/png'.

      • OptionalencoderOptions: number

        The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg. Default 0.92.

      Returns this

    • Takes a snapshot of the given area of the given canvas.

      Unlike the other snapshot methods, this one is processed immediately and doesn't wait for the next render.

      Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

      Parameters

      • canvas: HTMLCanvasElement

        The canvas to grab from.

      • callback: SnapshotCallback

        The Function to invoke after the snapshot image is created.

      • OptionalgetPixel: boolean

        Grab a single pixel as a Color object, or an area as an Image object? Default false.

      • Optionalx: number

        The x coordinate to grab from. Default 0.

      • Optionaly: number

        The y coordinate to grab from. Default 0.

      • Optionalwidth: number

        The width of the area to grab. Default canvas.width.

      • Optionalheight: number

        The height of the area to grab. Default canvas.height.

      • Optionaltype: string

        The format of the image to create, usually image/png or image/jpeg. Default 'image/png'.

      • OptionalencoderOptions: number

        The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg. Default 0.92.

      Returns this

    • Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered.

      To capture the whole game viewport see the snapshot method. To capture a specific area, see snapshotArea.

      Only one snapshot can be active per frame. If you have already called snapshotArea, for example, then calling this method will override it.

      Unlike the other two snapshot methods, this one will return a Color object containing the color data for the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute, using less memory.

      Parameters

      • x: number

        The x coordinate of the pixel to get.

      • y: number

        The y coordinate of the pixel to get.

      • callback: SnapshotCallback

        The Function to invoke after the snapshot pixel data is extracted.

      Returns this