Kiwi.Stage Class
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
Parameters:
-
game
Kiwi.GameThe game that this Stage belongs to.
-
name
StringThe name of the kiwi game.
-
width
NumberThe initial width of the game.
-
height
NumberThe initial heihgt of the game.
-
scaleType
NumberThe scale method that should be used for the game.
Returns:
Item Index
Methods
Properties
- _alpha
- _color
- _game
- _height
- _renderer
- _scaleType
- _visibility
- _visibilityChange
- _width
- _x
- _y
- alpha
- canvas
- color
- container
- ctx
- dctx
- debugCanvas
- DEFAULT_HEIGHT static
- DEFAULT_WIDTH static
- domReady
- gl
- height
- name
- normalizedColor
- offset
- onBlur
- onFocus
- onResize
- onVisibilityChange
- onWindowResize
- renderer
- rgbaColor
- rgbColor
- scale
- SCALE_FIT static
- SCALE_NONE static
- SCALE_STRETCH static
- scaleType
- scaleX
- scaleY
- visibility
- width
- x
- y
Methods
_calculateContainerScale
()
private
Used to calculate new offset and scale for the stage.
_checkVisibility
-
event
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
Adds the focus, blur, and visibility events to the document.
_orientationChanged
-
event
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
Method that is fired when the window is resized.
Parameters:
-
event
UIEvent
boot
-
dom
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
HTMLElementThe
clearDebugCanvas
-
[color="rgba(255,0,0,0.2)"]
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 optionalThe 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
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:
-
element
Any -
output
Kiwi.Geom.Point
Returns:
objType
()
String
public
Returns the type of this object.
Returns:
"Stage"
resize
-
width
-
height
Set the stage width and height for rendering purposes. This will not effect that "scaleType" that it has been set to.
Parameters:
-
width
NumberThe new Stage width.
-
height
NumberThe new Stage height.
setRGBColor
-
r
-
g
-
b
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
NumberThe red component. A value between 0 and 255.
-
g
NumberThe green component. A value between 0 and 255.
-
b
NumberThe blue component. A value between 0 and 255.
Returns:
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
_height
Number
private
The height of the stage
_renderer
Any
private
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
Contains string used to access the hidden
property on the document.
Default: 'hidden'
_visibilityChange
Any
private
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.
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
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
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
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.