Class Index | File Index

Classes


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.

Class Summary
Constructor Attributes Constructor Name and Description
 
DisplayObject is an abstract class that should not be constructed directly.
Field Summary
Field Attributes Field Name and Description
 
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.
 
The composite operation indicates how the pixels of this display object will be composited with the elements behind it.
 
id
Unique ID for this display object.
 
Indicates whether to include this object when running Stage.getObjectsUnderPoint().
 
An optional name for this display object.
 
The onClick callback is called when the user presses down on and then releases the mouse button over this display object.
 
The onPress callback is called when the user presses down on their mouse over 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.
 
The factor to skew this display object horizontally.
 
The factor to skew this display object vertically.
 
Indicates whether the display object should have it's x & y position rounded prior to drawing it to stage.
<static>  
Suppresses errors generated when using features like hitTest, onPress/onClick, and getObjectsUnderPoint with cross domain content.
 
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 Summary
Method Attributes Method Name and Description
 
cache(x, y, width, height)
Draws the display object into a new canvas, which is then used for subsequent draws.
 
Returns a clone of this DisplayObject.
 
draw(ctx, ignoreCache)
NOTE: This method is mainly for internal use, though it may be useful for advanced developers.
 
Generates a concatenated Matrix2D object representing the combined transform of the display object and all of its parent Containers up to the highest level ancestor (usually the stage).
 
Returns the stage that this display object will be rendered on, or null if it has not been added to one.
 
Transforms the specified x and y position from the global (stage) coordinate space to the coordinate space of the display object.
 
hitTest(x, y)
Tests whether the display object intersects the specified local point (ie.
 
NOTE: This method is mainly for internal use, though it may be useful for advanced developers.
 
Transforms the specified x and y position from the coordinate space of the display object to the global (stage) coordinate space.
 
localToLocal(x, y, target)
Transforms the specified x and y position from the coordinate space of this display object to the coordinate space of the target display object.
 
Returns a string representation of this object.
 
Clears the current cache.
 
updateCache(compositeOperation)
Redraws the display object to its cache.
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
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.

compositeOperation
The composite operation indicates how the pixels of this display object will be composited with the elements behind it. If null, this property is inherited from the parent container. For more information, read the whatwg spec on compositing.

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.

onClick
The onClick callback is called when the user presses down on and then releases the mouse button over this display object. The handler is passed a single param containing the corresponding MouseEvent instance. If an onClick handler is set on a container, it will receive the event if any of its children are clicked.

onPress
The onPress callback is called when the user presses down on their mouse over this display object. The handler is passed a single param containing the corresponding MouseEvent instance. You can subscribe to the onMouseMove and onMouseUp callbacks of the event object to receive these events until the user releases the mouse button. If an onPress handler is set on a container, it will receive the event if any of its children are clicked.

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. If null, this property is inherited from the parent container.

skewX
The factor to skew this display object horizontally.

skewY
The factor to skew this display object vertically.

snapToPixel
Indicates whether the display object should have it's x & y position rounded prior to drawing it to stage. This only applies if the enclosing stage has snapPixelsEnabled set to true, and the display object's composite transform does not include any scaling, rotation, or skewing. The snapToPixel property is true by default for Bitmap and BitmapSequence instances, and false for all other display objects.

<static> DisplayObject.suppressCrossDomainErrors
Suppresses errors generated when using features like hitTest, onPress/onClick, and getObjectsUnderPoint with cross domain content.

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
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 re-rendered 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 updateCache() or cache() again. 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).

draw(ctx, ignoreCache)
NOTE: This method is mainly for internal use, though it may be useful for advanced developers. Draws the display object into the specified context ignoring it's visible, alpha, shadow, and transform. Returns true if the draw was handled (useful for overriding functionality).
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).

getConcatenatedMatrix(mtx)
Generates a concatenated Matrix2D object representing the combined transform of the display object and all of its parent Containers up to the highest level ancestor (usually the stage). This can be used to transform positions between coordinate spaces, such as with localToGlobal and globalToLocal.
Parameters:
mtx
Optional. A Matrix2D object to populate with the calculated values. If null, a new Matrix object is returned.

getStage()
Returns the stage that this display object will be rendered on, or null if it has not been added to one.

globalToLocal(x, y)
Transforms the specified x and y position from the global (stage) coordinate space to the coordinate space of the display object. For example, this could be used to determine the current mouse position within the display object. Returns a Point instance with x and y properties correlating to the transformed position in the display object's coordinate space.
Parameters:
x
The x position on the stage to transform.
y
The y position on the stage to transform.

hitTest(x, y)
Tests whether the display object intersects the specified local point (ie. draws a pixel with alpha > 0 at the specified position). This ignores the alpha, shadow and compositeOperation of the display object, and all transform properties including regX/Y.
Parameters:
x
The x position to check in the display object's local coordinates.
y
The y position to check in the display object's local coordinates.

isVisible()
NOTE: This method is mainly for internal use, though it may be useful for advanced developers. Returns true or falsee indicating whether the display object would be visible if drawn to a canvas. This does not account for whether it would be visible within the boundaries of the stage.

localToGlobal(x, y)
Transforms the specified x and y position from the coordinate space of the display object to the global (stage) coordinate space. For example, this could be used to position an HTML label over a specific point on a nested display object. Returns a Point instance with x and y properties correlating to the transformed coordinates on the stage.
Parameters:
x
The x position in the source display object to transform.
y
The y position in the source display object to transform.

localToLocal(x, y, target)
Transforms the specified x and y position from the coordinate space of this display object to the coordinate space of the target display object. Returns a Point instance with x and y properties correlating to the transformed position in the target's coordinate space. Effectively the same as calling var pt = this.localToGlobal(x, y); pt = target.globalToLocal(pt.x, pt.y);
Parameters:
x
The x position in the source display object to transform.
y
The y position on the stage to transform.
target
The target display object to which the coordinates will be transformed.

toString()
Returns a string representation of this object.

uncache()
Clears the current cache. See cache() for more information.

updateCache(compositeOperation)
Redraws the display object to its cache. Calling updateCache without an active cache will throw an error. If compositeOperation is null the current cache will be cleared prior to drawing. Otherwise the display object will be drawn over the existing cache using the specified compositeOperation.
Parameters:
compositeOperation
The compositeOperation to use, or null to clear the cache and redraw it. whatwg spec on compositing.

Documentation generated by JsDoc Toolkit 2.3.2 on Sun Feb 13 2011 22:46:00 GMT-0700 (MST)