Class DisplayObject
DisplayObject is the base class for all display classes in the CanvasDisplay library. It defines the core properties and methods that are shared between all display objects. It should not be instantiated directly.
Defined in: DisplayObject.js.
Constructor Attributes | Constructor Name and Description |
---|---|
DisplayObject is an abstract class that should not be constructed directly.
|
Field Attributes | Field Name and Description |
---|---|
<private> | |
<private> | |
<private> | |
<private> | |
<private> | |
<private> | |
<private> | |
<private> | |
The alpha (transparency) for this display object.
|
|
If a cache is active, this returns the canvas that holds the cached version of this display object.
|
|
Unique ID for this display object.
|
|
Indicates whether to include this object when running Stage.getObjectsUnderPoint().
|
|
An optional name for this display object.
|
|
A reference to the Sprite or Stage object that contains this display object, or null if it has not been added to one.
|
|
The x offset for this display object's registration point.
|
|
The y offset for this display object's registration point.
|
|
The rotation in degrees for this display object.
|
|
The factor to stretch this display object horizontally.
|
|
The factor to stretch this display object vertically.
|
|
A shadow object that defines the shadow to render on this display object.
|
|
Indicates whether this display object should be rendered to the canvas and included when running Stage.getObjectsUnderPoint().
|
|
The x (horizontal) position of the display object, relative to its parent.
|
|
The y (vertical) position of the display object, relative to its parent.
|
Method Attributes | Method Name and Description |
---|---|
<private> |
applyShadow(ctx, shadow)
|
cache(x, y, width, height)
Draws the display object into a new canvas, which is then used for subsequent draws.
|
|
clone()
Returns a clone of this DisplayObject.
|
|
<private> |
cloneProps(o)
|
draw(ctx, ignoreCache)
NOTE: This method is mainly for internal use, though it may be useful for advanced developers extending the capabilities of the CanvasDisplay library.
|
|
getStage()
Returns the stage that this display object will be rendered on, or null if it has not been added to one.
|
|
<private> |
init()
|
NOTE: This method is mainly for internal use, though it may be useful for advanced developers extending the capabilities of the CanvasDisplay library.
|
|
toString()
Returns a string representation of this object.
|
|
uncache()
Clears the current cache.
|
|
updateContext(ctx, ignoreShadows)
NOTE: This method is mainly for internal use, though it may be useful for advanced developers extending the capabilities of the CanvasDisplay library.
|
Class Detail
DisplayObject()
DisplayObject is an abstract class that should not be constructed directly. Instead construct subclasses such as Sprite, Bitmap, and Shape.
Field Detail
<private>
_activeContext
<private>
_cacheDraw
<private>
_cacheOffsetX
<private>
_cacheOffsetY
<private>
_restoreContext
<private>
_revertShadow
<private>
_revertX
<private>
_revertY
alpha
The alpha (transparency) for this display object. 0 is fully transparent, 1 is fully opaque. *
cacheCanvas
If a cache is active, this returns the canvas that holds the cached version of this display object. See cache() for more information. READ-ONLY. *
id
Unique ID for this display object. Makes display objects easier for some uses. *
mouseEnabled
Indicates whether to include this object when running Stage.getObjectsUnderPoint(). Setting this to true for Sprites will cause the Sprite to be returned (not its children) regardless of whether it's mouseChildren property is true. *
name
An optional name for this display object. Included in toString(). Useful for debugging. *
parent
A reference to the Sprite or Stage object that contains this display object, or null if it has not been added to one. READ-ONLY. *
regX
The x offset for this display object's registration point. For example, to make a 100x100px Bitmap rotate around it's center, you would set regX and regY to 50. *
regY
The y offset for this display object's registration point. For example, to make a 100x100px Bitmap rotate around it's center, you would set regX and regY to 50. *
rotation
The rotation in degrees for this display object. *
scaleX
The factor to stretch this display object horizontally. For example, setting scaleX to 2 will stretch the display object to twice it's nominal width. *
scaleY
The factor to stretch this display object vertically. For example, setting scaleY to 0.5 will stretch the display object to half it's nominal height. *
shadow
A shadow object that defines the shadow to render on this display object. Set to null to remove a shadow. Note that nested shadows can result in unexpected behaviour (ex. if both a child and a parent have a shadow set). *
visible
Indicates whether this display object should be rendered to the canvas and included when running Stage.getObjectsUnderPoint(). *
x
The x (horizontal) position of the display object, relative to its parent. *
y
The y (vertical) position of the display object, relative to its parent. *
Method Detail
<private>
applyShadow(ctx, shadow)
- Parameters:
- ctx
- shadow
cache(x, y, width, height)
Draws the display object into a new canvas, which is then used for subsequent draws. For complex content that does not change frequently (ex. a Sprite with many children that do not move, or a complex vector Shape), this can provide for much faster rendering because the content does not need to be rerendered each tick. The cached display object can be moved, rotated, faded, etc freely, however if it's content changes, you must manually update the cache by calling cache() again. Do not call uncache before the subsequent cache call. You must specify the cache area via the x, y, w, and h parameters. This defines the rectangle that will be rendered and cached using this display object's coordinates. For example if you defined a Shape that drew a circle at 0,0 with a radius of 25, you could call myShape.cache(-25,-25,50,50) to cache the full shape.
- Parameters:
- x
- y
- width
- height
clone()
Returns a clone of this DisplayObject. Some properties that are specific to this instance's current context are reverted to their defaults (for example .parent).
<private>
cloneProps(o)
- Parameters:
- o
draw(ctx, ignoreCache)
NOTE: This method is mainly for internal use, though it may be useful for advanced developers extending the capabilities of the CanvasDisplay library.
Draws the display object into the specified context if it is visible.
- Parameters:
- ctx
- The canvas 2D context object to draw into.
- ignoreCache
- Indicates whether the draw operation should ignore any current cache. For example, used for drawing the cache (to prevent it from simply drawing an existing cache back into itself).
getStage()
Returns the stage that this display object will be rendered on, or null if it has not been added to one.
<private>
init()
revertContext()
NOTE: This method is mainly for internal use, though it may be useful for advanced developers extending the capabilities of the CanvasDisplay library.
Reverts the last context that was updated with updateContext(), restoring it to the state it was in prior to the update.
toString()
Returns a string representation of this object.
uncache()
Clears the current cache. See cache() for more information.
updateContext(ctx, ignoreShadows)
NOTE: This method is mainly for internal use, though it may be useful for advanced developers extending the capabilities of the CanvasDisplay library.
Updates the specified context based on this display object's properties.
- Parameters:
- ctx
- The canvas 2D context object to update.
- ignoreShadows
- Indicates whether the shadow property should be applied. Passing false will ignore the shadow, resulting in faster rendering for uses like hit testing.