Interface Renderer

The description of an implementation that can provide rendering for the graphics context

interface Renderer {
    alpha(alpha): void;
    clearRect(x, y, width, height): void;
    createOffscreen(width, height): Offscreen;
    drawImage(image, x, y, width?, height?, col?): void;
    drawOffscreen(offscreen, x, y): void;
    drawOffscreenSection(offscreen, x, y, sx, sy, width, height): void;
    drawRect(x, y, width, height, col): void;
    drawTile(tiles, x, y, tile, width, height, col?): void;
    drawToMain(): void;
    drawToOffscreen(offscreen): void;
    fillRect(x, y, width, height, col): void;
    getDrawCount(): number;
    init(canvas, pixelatedRenderingEnabled, textureSize?, texturePaddingSize?): Renderer;
    initResourceOnLoaded(): void;
    loadImage(url, track, id?, smooth?): GameImage;
    loadTileSet(url, tw, th, id?): TileSet;
    pop(): void;
    postRender(): void;
    preRender(): void;
    push(): void;
    ready(): boolean;
    resize(): void;
    rotate(ang): void;
    scale(x, y): void;
    translate(x, y): void;
}

Methods

  • Set the alpha to apply when drawing

    Parameters

    • alpha: number

      The alpha to apply (0-1)

    Returns void

  • Clear a rectangle on the current graphics context. Resets pixels completely.

    Parameters

    • x: number

      The x coordinate of the rectangle to clear

    • y: number

      The y coordinate of the rectangle to clear

    • width: number

      The width of the rectangle to clear

    • height: number

      The height of the rectangle to clear

    Returns void

  • Create an offscreen rendering context

    Parameters

    • width: number

      The width of the new context in pixels

    • height: number

      The height of the new context in pixels

    Returns Offscreen

    The newly created offscreen canvas

  • Draw an image to the graphics context

    Parameters

    • image: GameImage

      The image to be drawn

    • x: number

      The x coordinate to draw at

    • y: number

      The y coordinate to draw at

    • Optional width: number

      The width of the image to draw

    • Optional height: number

      The height of the image to draw

    • Optional col: string

      The color to tint the image - in CSS format

    Returns void

  • Draw an offscreen context to the current context

    Parameters

    • offscreen: Offscreen

      The offscreen context to draw

    • x: number

      The x coordinate to draw at

    • y: number

      The y coordinate to draw at

    Returns void

  • Draw a section of an offscreen context to the current context

    Parameters

    • offscreen: Offscreen

      The offscreen context to draw

    • x: number

      The x coordinate to draw at

    • y: number

      The y coordinate to draw at

    • sx: number

      The x coordinate in the offscreen canvas to start drawing from

    • sy: number

      The y coordinate in the offscreen canvas to start drawing from

    • width: number

      The width of the section to draw

    • height: number

      The height of the section to draw

    Returns void

  • Draw the outline of a rectangle to the graphics context

    Parameters

    • x: number

      The x coordinate to draw at

    • y: number

      The y coordinate to draw at

    • width: number

      The width of the rectangle to draw

    • height: number

      The height of the rectangle to draw

    • col: string

      The color to draw the rectangle in - in CSS format

    Returns void

  • Draw a tile to the graphics context

    Parameters

    • tiles: TileSet

      The tile set containing the tile to draw

    • x: number

      The x coordinate to draw at

    • y: number

      The y coordinate to draw at

    • tile: number

      The index of the tile to render

    • width: number

      The width to render the tile at in pixels

    • height: number

      The height to render the tile at in pixels

    • Optional col: string

    Returns void

  • Configure the graphics context to render to the screen

    Returns void

  • Configure the graphics context to render to the offscreen canvas provided

    Parameters

    • offscreen: Offscreen

      The offscreen canvas that this context should render to

    Returns void

  • Draw a rectangle to the graphics context

    Parameters

    • x: number

      The x coordinate to draw at

    • y: number

      The y coordinate to draw at

    • width: number

      The width of the rectangle to draw

    • height: number

      The height of the rectangle to draw

    • col: string

      The color to fill the rectangle in - in CSS format

    Returns void

  • Get the number of draws thats have been applied in the last frame

    Returns number

  • Initialize the renderer

    Parameters

    • canvas: HTMLCanvasElement

      The canvas that will be rendered to

    • pixelatedRenderingEnabled: boolean

      True if images will be scaled with nearest neighbor rather than attempting to smooth

    • Optional textureSize: number

      A hint to the max texture size to use. This is useful when you want to reduce the graphics memory requirements.

    • Optional texturePaddingSize: number

      A hint to help with texture artifacts. Add some padding around textures.

    Returns Renderer

    The created renderer

  • Re-initialize any renderer resources on load of new images

    Returns void

  • Load an image from a given URL

    Parameters

    • url: string

      The URL to the image to be loaded

    • track: boolean

      True if we want to track the resource loading and report it

    • Optional id: string

      The ID to give the new image

    • Optional smooth: boolean

      True if we want to override pixel based scaling and attempt to render scaled versions smoothly

    Returns GameImage

    The loaded tile image

  • Load an tile set from a given URL

    Parameters

    • url: string

      The URL of the image to load

    • tw: number

      The width of each tile in the image

    • th: number

      The height of each tile int he image

    • Optional id: string

      The ID to give the loaded image

    Returns TileSet

    The loaded tile set

  • Restore the state of the context (transforms, alpha etc) from the stack.

    Returns void

  • Called after the game renders

    Returns void

  • Called before the game renders

    Returns void

  • Store the current state of the context (transforms, alpha etc) to the stack.

    Returns void

  • Check if this renderer is ready to draw

    Returns boolean

    True if the renderer is fully initialized

  • Notification that the screen has resized allowing the renderer to regenerate any resources.

    Returns void

  • Apply a rotation transform to the current graphics context

    Parameters

    • ang: number

      The angle to rotate the context by

    Returns void

  • Apply a scaling transform to the current graphics context

    Parameters

    • x: number

      The amount to scale on the x axis

    • y: number

      The amount to scale on the y axis

    Returns void

  • Apply a translation transform to the current graphics context

    Parameters

    • x: number

      The amount to transform on the x axis

    • y: number

      The amount to transform on the y axis

    Returns void

Generated using TypeDoc