API Docs for: 1.4.0
Show:

Kiwi.Stage Class

Defined in: src\core\Stage.ts:9
Module: Kiwi

Each game contains a single Stage which controls the creation and management of main domElements required for a Kiwi game to work. This includes the Canvas and the rendering contexts, as well as the width/height of the game and the position it should be on the screen.

Constructor

Kiwi.Stage

(
  • game
  • name
  • width
  • height
  • scaleType
)
Kiwi.Stage

Defined in src\core\Stage.ts:9

Parameters:

  • game Kiwi.Game

    The game that this Stage belongs to.

  • name String

    The name of the kiwi game.

  • width Number

    The initial width of the game.

  • height Number

    The initial heihgt of the game.

  • scaleType Number

    The scale method that should be used for the game.

Returns:

Methods

_calculateContainerScale

() private

Used to calculate new offset and scale for the stage.

_checkVisibility

(
  • event
)
private

Defined in src\core\Stage.ts:973

Available since 1.3.0

Fired when the page visibility changes, or the page focus/blur events fire. In charge of firing the appropriate signals.

Parameters:

  • event Any

_createCompositeCanvas

() private

Handles the creation of the canvas that the game will use and retrieves the context for the renderer.

_createFocusEvents

() private

Defined in src\core\Stage.ts:1001

Available since 1.3.0

Adds the focus, blur, and visibility events to the document.

_orientationChanged

(
  • event
)
private

Defined in src\core\Stage.ts:632

Available since 1.1.1

Method that is fired when the device is reoriented.

Parameters:

  • event UIEvent

_scaleContainer

() private

Handles the scaling/sizing based upon the scaleType property.

_windowResized

(
  • event
)
private

Method that is fired when the window is resized.

Parameters:

  • event UIEvent

boot

(
  • dom
)
public

Is executed when the DOM has loaded and the game is just starting. This is a internal method used by the core of Kiwi itself.

Parameters:

  • dom HTMLElement

    The

clearDebugCanvas

(
  • [color="rgba(255,0,0,0.2)"]
)
public

Clears the debug canvas and fills with either the color passed. If not colour is passed then Red at 20% opacity is used.

Parameters:

  • [color="rgba(255,0,0,0.2)"] String optional

    The debug color to rendering on the debug canvas.

createDebugCanvas

() public

Creates a debug canvas and adds it above the regular game canvas. The debug canvas is not created by default (even with debugging on) and rendering/clearing of the canvas is upto the developer. The context for rendering can be access via the "dctx" property and you can use the "clearDebugCanvas" method to clear the canvas.

getOffsetPoint

(
  • element
  • output
)
Kiwi.Geom.Point public

Gets the x/y coordinate offset of any given valid DOM Element from the top/left position of the browser Based on jQuery offset https://github.com/jquery/jquery/blob/master/src/offset.js

Parameters:

Returns:

objType

() String public

Returns the type of this object.

Returns:

String:

"Stage"

resize

(
  • width
  • height
)
public

Set the stage width and height for rendering purposes. This will not effect that "scaleType" that it has been set to.

Parameters:

  • width Number

    The new Stage width.

  • height Number

    The new Stage height.

setRGBColor

(
  • r
  • g
  • b
)
Object public

Sets the background color of the stage through component RGB colour values. Each parameter is a number between 0 and 255. This method also returns an Object Literal with "r", "g", "b" properties.

Parameters:

  • r Number

    The red component. A value between 0 and 255.

  • g Number

    The green component. A value between 0 and 255.

  • b Number

    The blue component. A value between 0 and 255.

Returns:

Object:

A Object literal containing the r,g,b properties.

toggleDebugCanvas

() public

Toggles the visibility of the debug canvas.

Properties

_alpha

Number private

The alpha of the stage.

Default: 1

_color

Kiwi.Utils.Color public

The background color of the stage.

_game

Kiwi.Game private

The game this Stage belongs to

_height

Number private

The height of the stage

_renderer

Any private

Defined in src\core\Stage.ts:533

Available since 1.1.0

Stores the renderer created after context detection.

_scaleType

Number private

Private property that holds the scaling method that should be applied to the container element.

Default: Kiwi.Stage.SCALE_NONE

_visibility

String private

Defined in src\core\Stage.ts:952

Available since 1.3.0

Contains string used to access the hidden property on the document.

Default: 'hidden'

_visibilityChange

Any private

Defined in src\core\Stage.ts:963

Available since 1.3.0

Contains the bound version of the _checkVisibility method.

_width

Number private

The width of the stage.

_x

Number private

The X coordinate of the stage.

_y

Number private

The Y coordinate of the stage.

alpha

Number public

Sets the alpha of the container element. 0 = invisible, 1 = fully visible. Note: Because the alpha value is applied to the container, it will not work in CocoonJS.

Default: 1

canvas

HTMLCanvasElement public

The canvas element that is being rendered on.

color

String public

Sets the background color of the stage.

This can be any valid parameter for Kiwi.Utils.Color. If passing multiple parameters, do so in a single array.

The default value is "ffffff" or pure white.

Note for users of CocoonJS: When using the WebGL renderer, the stage color will fill all parts of the screen outside the canvas. Kiwi.js will automatically set the color to "000000" or pure black when using CocoonJS. If you change it, and your game does not fill the entire screen, the empty portions of the screen will also change color.

container

HTMLDivElement public

The parent div in which the layers and input live

ctx

CanvasRenderingContext2D public

The canvas rendering context.

dctx

CanvasRenderingContext2D public

The debug canvas rendering context.

debugCanvas

HTMLCanvasElement public

The debugging canvas.

DEFAULT_HEIGHT

Number public static

The default height of the stage.

Default: 600

DEFAULT_WIDTH

Number public static

The default width of the stage.

Default: 800

domReady

Boolean public

Whether or not this Stage is DOM ready.

gl

WebGLRenderingContext public

The webgl rendering context.

height

Number public

The height of the stage. This is READ ONLY. See the resize method if you need to modify this value.

name

String public

The title of your stage

normalizedColor

String public

Get the normalized background color of the stage. Returns an object with rgba values, each being between 0 and 1. This is READ ONLY.

offset

Kiwi.Geom.Point public

A point which determines the offset of this Stage

onBlur

Kiwi.Signal public

Defined in src\core\Stage.ts:910

Available since 1.3.0

Dispatches callbacks when this page containing this game loses focus.

onFocus

Kiwi.Signal public

Defined in src\core\Stage.ts:900

Available since 1.3.0

Dispatches callbacks when the page containing this game gains focus.

onResize

Kiwi.Signal public

A Signal that dispatches an event when the stage gets resized.

onVisibilityChange

Kiwi.Signal public

Defined in src\core\Stage.ts:920

Available since 1.3.0

Dispatches callbacks when the visiblity of the page changes.

onWindowResize

Kiwi.Signal public

A Signal which dispatches events when the window is resized. Useful to detect if the screen is now in a "landscape" or "portrait" view on Mobile/Cocoon devices.

renderer

Number public

Defined in src\core\Stage.ts:542

Available since 1.1.0

Get the renderer associated with the canvas context. This is either a GLRenderManager or a CanvasRenderer. If the Kiwi.RENDERER_WEBGL renderer was requested but could not be created, it will fall back to CanvasRenderer. This is READ ONLY.

rgbaColor

Object public

Defined in src\core\Stage.ts:437

Available since 1.1.0

Allows the setting of the background color of the stage through component RGBA colour values.

This property is an Object Literal with "r", "g", "b", "a" colour streams of values between 0 and 255.

Note that the alpha value is from 0-255, not 0-1. This is to preserve compatibility with hex-style color values, e.g. "ff0000ff".

rgbColor

Object public

Allows the setting of the background color of the stage through component RGB colour values.

This property is an Object Literal with "r", "g", "b" colour streams of values between 0 and 255.

scale

Kiwi.Geom.Point public

Calculates and returns the amount that the container has been scaled by. Mainly used for re-calculating input coordinates. Note: For COCOONJS this returns 1 since COCOONJS translates the scale itself. This property is READ ONLY.

Default: 1

SCALE_FIT

Number public static

Scale Fit will scale the stage's width to fit its parents width. The height is then calculated to maintain the aspect ratio of the width/height of the Stage.

Default: 1

SCALE_NONE

Number public static

The default scaling method used on Kiwi Games. This scaling method will set the container's width/height to static values.

Default: 0

SCALE_STRETCH

Number public static

Stretch will make the stage scale to fit its parents width/height (by using max/min height of 100%). If the parent doesn't have a height set then the height will be the height of the stage.

Default: 2

scaleType

Number public

Holds type of scaling that should be applied the container element.

Default: Kiwi.Stage.SCALE_NONE

scaleX

Number public

Calculates and returns the amount that the container has been scaled by on the X axis.

Default: 1

scaleY

Number public

Calculates and returns the amount that the container has been scaled by on the Y axis.

Default: 1

visibility

Boolean public

Defined in src\core\Stage.ts:930

Available since 1.3.0

A flag indicating if the page is currently visible (using the Visiblity API). If the Visiblity API is unsupported this will remain set to true regardless of focus / blur events.

Default: true

width

Number public

The width of the stage. This is READ ONLY. See the "resize" method if you need to modify this value.

x

Number public

The X coordinate of the stage. This number should be the same as the stage's left property.

y

Number public

Get the Y coordinate of the stage. This number should be the same as the stage's top property.