Class Stage
- extends Container
A stage is the root level Container for a display list. Each time its tick method is called, it will render its display
list to its target canvas.
Constructor
Stage
(
canvas
)
- Parameters:
-
canvas
<HTMLCanvasElement>
The canvas the stage will render to.
Properties
Indicates whether the stage should automatically clear the canvas before each render. You can set this to false to manually
control clearing (for generative art, or when pointing multiple stages at the same canvas for example).
Default Value: true
canvas
- HTMLCanvasElement
The canvas the stage will render to. Multiple stages can share a single canvas, but you must disable autoClear for all but the
first stage that will be ticked (or they will clear each other's render).
Indicates whether the mouse is currently within the bounds of the canvas.
Default Value: false
mouseX
- final Number
READ-ONLY. The current mouse X position on the canvas. If the mouse leaves the canvas, this will indicate the most recent
position over the canvas, and mouseInBounds will be set to false.
mouseY
- final Number
READ-ONLY. The current mouse Y position on the canvas. If the mouse leaves the canvas, this will indicate the most recent
position over the canvas, and mouseInBounds will be set to false.
Indicates whether this stage should use the snapToPixel property of display objects when rendering them.
Default Value: false
If false, tick callbacks will be called on all display objects on the stage prior to rendering to the canvas.
Default Value: false
Properties inherited from DisplayObject:
_cacheDataURL,
_cacheDataURLID,
_cacheOffsetX,
_cacheOffsetY,
_matrix,
alpha,
cacheCanvas,
cacheID,
compositeOperation,
filters,
id,
mouseEnabled,
name,
parent,
regX,
regY,
rotation,
scaleX,
scaleY,
shadow,
skewX,
skewY,
snapToPixel,
visible,
x,
y
Methods
protected
void
_enableMouseEvents
(
enabled
)
- Parameters:
-
enabled
<Boolean>
- Returns:
void
protected
void
_handleDoubleClick
(
e
)
- Parameters:
-
e
<MouseEvent>
- Returns:
void
protected
void
_handleMouseDown
(
e
)
- Parameters:
-
e
<MouseEvent>
- Returns:
void
protected
void
_handleMouseMove
(
e
)
- Parameters:
-
e
<MouseEvent>
- Returns:
void
protected
void
_handleMouseUp
(
e
)
- Parameters:
-
e
<MouseEvent>
- Returns:
void
protected
void
_testMouseOver
(
)
protected
void
_updateMousePosition
(
pageX
,
pageY
)
- Parameters:
-
pageX
<Number>
-
pageY
<Number>
- Returns:
void
void
clear
(
)
Clears the target canvas. Useful if autoClear is set to false.
Stage
clone
(
)
Returns a clone of this Stage.
- Returns:
Stage
- A clone of the current Container instance.
void
enableMouseOver
(
frequency
)
Enables or disables (by passing a frequency of 0) mouse over handlers (onMouseOver and onMouseOut) for this stage's display
list. These events can be expensive to generate, so they are disabled by default, and the frequency of the events
can be controlled independently of mouse move events via the optional frequency parameter.
- Parameters:
-
frequency
<Number>
Optional param specifying the maximum number of times per second to broadcast mouse over/out events. Set to 0 to disable mouse
over events completely. Maximum is 50. A lower frequency is less responsive, but uses less CPU. Default is 20.
- Returns:
void
protected
void
initialize
param {HTMLCanvasElement} canvas A canvas object, or the string id of a canvas object in the current document.
(
)
Initialization method.
String
toDataURL
(
backgroundColor
,
mimeType
)
Returns a data url that contains a Base64 encoded image of the contents of the stage. The returned data url can be
specified as the src value of an image element.
- Parameters:
-
backgroundColor
<String>
The background color to be used for the generated image. The value can be any value HTML color
value, including HEX colors, rgb and rgba. The default value is a transparent background.
-
mimeType
<String>
The MIME type of the image format to be create. The default is "image/png". If an unknown MIME type
is passed in, or if the browser does not support the specified MIME type, the default value will be used.
- Returns:
String
- a Base64 encoded image.
String
toString
(
)
Returns a string representation of this object.
- Returns:
String
- a string representation of the instance.
void
update
(
)
Each time the update method is called, the stage will tick any descendants exposing a tick method (ex. BitmapAnimation)
and render its entire display list to the canvas.
_applyFilters,
_testHit,
_tick,
applyShadow,
cache,
clone,
cloneProps,
draw,
getCacheDataURL.,
getConcatenatedMatrix,
getStage,
globalToLocal,
hitTest,
initialize,
isVisible,
localToGlobal,
localToLocal,
setTransform,
toString,
uncache,
updateCache
Methods inherited from Container:
_getObjectsUnderPoint,
_tick,
addChild,
addChildAt,
clone,
contains,
draw,
getChildAt,
getChildIndex,
getNumChildren,
getObjectsUnderPoint,
getObjectUnderPoint,
hitTest,
initialize,
isVisible,
removeAllChildren,
removeChild,
removeChildAt,
setChildIndex,
sortChildren,
swapChildren,
swapChildrenAt,
toString
Events
onMouseDown
(
event
)
The onMouseDown callback is called when the user presses the mouse button over the canvas. The handler is passed a single
param containing the corresponding MouseEvent instance.
- Parameters:
-
event
<MouseEvent>
A MouseEvent instance with information about the current mouse event.
onMouseMove
(
event
)
The onMouseMove callback is called when the user moves the mouse over the canvas. The handler is passed a single param
containing the corresponding MouseEvent instance.
- Parameters:
-
event
<MouseEvent>
A MouseEvent instance with information about the current mouse event.
onMouseUp
(
event
)
The onMouseUp callback is called when the user releases the mouse button anywhere that the page can detect it. The handler
is passed a single param containing the corresponding MouseEvent instance.
- Parameters:
-
event
<MouseEvent>
A MouseEvent instance with information about the current mouse event.
tick
Broadcast to children when the stage is updated.
(
)