Stage


Inheritance Stage Container View Module hilo/view/Stage Requires hilo/core/Hilo, hilo/core/Class, hilo/view/Container, hilo/renderer/CanvasRenderer, hilo/renderer/DOMRenderer, hilo/renderer/WebGLRenderer, hilo/util/browser, hilo/util/util Source Stage.js
Stage is the root of all visual object tree, any visual object will be render only after being added to Stage or any children elements of Stage. Normally, every hilo application start with an stage instance.

Demo:

var stage = new Hilo.Stage({
    renderType:'canvas',
    container: containerElement,
    width: 320,
    height: 480
});

Properties

Show Inherited Properties
Property Defined
canvas:HTMLCanvasElement|HTMLElement
The canvas the Stage is related to.
Stage
paused:Boolean
Paused Stage rendering.
Stage
renderer:Renderer
Stage renderer, readonly!
Stage
viewport:Object
Rendering area of the Stage.
Stage

Methods

Show Inherited Methods
Method Defined
Stage(properties:Object)
Constructor
Stage
addTo(domElement:HTMLElement):Stage
Add Stage canvas to DOM container.
Stage
enableDOMEvent(type:String|Array, enabled:Boolean):Stage
Turn on/off Stage response to DOM event.
Stage
resize(width:Number, height:Number, forceResize:Boolean)
Resize the Stage.
Stage
tick(delta:Number)
Invoke tick function and Stage will update and render.
Stage
updateViewport():Object
Update the viewport (rendering area) which Stage show on the page.
Stage

Property Detail

canvas:HTMLCanvasElement|HTMLElement
The canvas the Stage is related to. It can be a canvas or a div element, readonly!
paused:Boolean
Paused Stage rendering.
renderer:Renderer
Stage renderer, readonly!
viewport:Object
Rendering area of the Stage. Including properties like: left, top, width, height. readonly!

Constructor

Stage(properties:Object)
parameters
properties:Object — Properties parameters for the object. Includes all writable properties of this class. Some important like:
  • container:String|HTMLElement - Assign the parent container element of the Stage in the page. It should be a dom container or an id. If this parameter is not given and canvas isn't in the dom tree, you should add the stage vanvas into the dom tree yourself, otherwise Stage will not render. optional.
  • renderType:String - Renering way: canvas|dom|webgl,default value is canvas, optional.
  • canvas:String|HTMLCanvasElement|HTMLElement - 指定舞台所对应的画布元素。它是一个canvas或普通的div,也可以传入元素的id。若为canvas,则使用canvas来渲染所有对象,否则使用dom+css来渲染。可选。
  • width:Number
  • - The width of the Stage, default value is the width of canvas, optional.
  • height:Number
  • - The height of the Stage, default value is the height of canvas, optional.
  • paused:Boolean
  • - Whether stop rendering the Stage, default value is false, optional.

Method Detail

addTo(domElement:HTMLElement):Stage
Add Stage canvas to DOM container. Note: this function overwrite View.addTo function.
parameters
domElement:HTMLElement — An dom element.
return
Stage — The Stage Object, chained call supported.
enableDOMEvent(type:String|Array, enabled:Boolean):Stage
Turn on/off Stage response to DOM event. To make visual objects on the Stage interactive, use this function to turn on Stage's responses to events.
parameters
type:String|Array — The event name or array that need to turn on/off.
enabled:Boolean — Whether turn on or off the response method of stage DOM event. If not provided, default value is true.
return
Stage — The Stage Object, chained call supported.
resize(width:Number, height:Number, forceResize:Boolean)
Resize the Stage.
parameters
width:Number — The width of the new Stage.
height:Number — The height of the new Stage.
forceResize:Boolean — Whether forced to resize the Stage, means no matter the size of the Stage, force to change the size to keep Stage, canvas and window act at the same time.
tick(delta:Number)
Invoke tick function and Stage will update and render. Developer may not need to use this funciton.
parameters
delta:Number — The time had pass between this tick invoke and last tick invoke.
updateViewport():Object
Update the viewport (rendering area) which Stage show on the page. Invoke this function to update viewport when Stage canvas changes border, margin or padding properties.
return
Object — The visible area of the Stage (the viewport property).