Class R.rendercontexts.AbstractRenderContext
Extends
R.struct.Container.
A base rendering context. Game objects are rendered to a context
during engine runtime. A render context is a container of all of the objects
added to it so that each object is given the chance to render. A render context
is logically a scene graph. While each context can have multiple contexts associated
with it, the root of the scene graph is always located at R.Engine#getDefaultContext.
Defined in: abstractrendercontext.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.rendercontexts.AbstractRenderContext(contextName, surface)
Creates a render context
|
- Fields borrowed from class R.struct.Container:
- EMPTY
Method Attributes | Method Name and Description |
---|---|
add(obj)
Add an object to the context.
|
|
Enable mouse event capturing within the render context.
|
|
Enable touch event capturing within the render context.
|
|
destroy()
Destroy the rendering context, any objects within the context, and detach
the surface from its parent container.
|
|
Get the class name of this object
|
|
getContextData(obj)
Returns the structure that contains information held about
the rendering context.
|
|
A viewport that is 25% larger than #getViewport to account for
an area slightly outside the viewing area.
|
|
Get the state of the mouse in the rendering context.
|
|
Get the surface node that all objects will be rendered to.
|
|
Get the state of touches in the rendering context.
|
|
Get the viewport of the render context.
|
|
getWorldBoundary(rect)
get the world boundaries.
|
|
Get the world render position.
|
|
Gets the world rotation angle.
|
|
Gets an array representing the rendering scale of the world.
|
|
isStatic()
Determine if the context is static.
|
|
Decrement the transform stack counter and ensure that the stack
is not unbalanced.
|
|
Increment the transform stack counter.
|
|
release()
Releases this context back into the pool for reuse
|
|
remove(obj)
Remove an object from the render context.
|
|
removeAtIndex(idx)
Remove an object from the render context at the specified index.
|
|
render(time, dt)
Called to render all of the objects to the context.
|
|
renderObject(obj, time, dt)
Render a single object into the world for the given time.
|
|
reset(rect)
[ABSTRACT] Clear the context and prepare it for rendering.
|
|
This is a potentially expensive call, and can lead to rendering
errors.
|
|
setScale(scaleX, scaleY)
[ABSTRACT] Set the scale of the rendering context.
|
|
setStatic(state)
Set the context to be static.
|
|
setSurface(element)
Set the surface element that objects will be rendered to.
|
|
setupWorld(time, dt)
[ABSTRACT] Gives the render context a chance to initialize the world.
|
|
setViewport(rect)
Set the viewport of the render context.
|
|
setWorldBoundary(rect)
Set the world boundaries.
|
|
setWorldPosition(point, y)
Set the world position of the rendering context.
|
|
setWorldRotation(rotation)
Set the world rotation of the rendering context.
|
|
setWorldScale(scale)
Set the world scale of the rendering context.
|
|
sort(sortFn)
[ABSTRACT] Sort the render context's objects.
|
|
Disable mouse event capturing within the render context.
|
|
Disable touch event capturing within the render context.
|
|
update(parentContext, time, dt)
Update the render context before rendering the objects to the surface.
|
- Methods borrowed from class R.struct.Container:
- addAll, append, cleanUp, clear, clone, concat, contains, filter, forEach, fromArray, get, getAll, getObjects, getProperties, insert, iterator, reduce, replace, replaceAt, size, subset, toXML
- Methods borrowed from class R.engine.BaseObject:
- addEvent, addEvents, getElement, jQ, removeEvent, setElement, triggerEvent
- Methods borrowed from class R.engine.PooledObject:
- clearObjectDataModel, getId, getName, getObjectDataModel, isDestroyed, setName, setObjectDataModel, toString
Class Detail
R.rendercontexts.AbstractRenderContext(contextName, surface)
Creates a render context
- Parameters:
- contextName
- {String} The name of this context. Default: RenderContext
- surface Optional
- {HTMLElement} The surface node that all objects will be rendered to.
Method Detail
add(obj)
Add an object to the context. Only objects
within the context will be rendered. If an object declared
an afterAdd() method, it will be called after the object
has been added to the context.
- Parameters:
- obj
- {R.engine.BaseObject} The object to add to the render list
captureMouse()
Enable mouse event capturing within the render context. The mouse
event data will be accessible by calling #getMouseInfo.
captureTouch()
Enable touch event capturing within the render context. The touch
event data will be accessible by calling #getTouchInfo.
destroy()
Destroy the rendering context, any objects within the context, and detach
the surface from its parent container.
{String}
getClassName()
Get the class name of this object
- Returns:
- {String} "R.rendercontexts.AbstractRenderContext"
{Object}
getContextData(obj)
Returns the structure that contains information held about
the rendering context. This object allows a context to store
extra information on an object that an object wouldn't know about.
- Parameters:
- obj
- Returns:
- {Object} An object with data used by the context
{R.math.Rectangle2D}
getExpandedViewport()
A viewport that is 25% larger than #getViewport to account for
an area slightly outside the viewing area. Typically used to determin
what objects are to be processed in the scenegraph.
- Returns:
- {R.math.Rectangle2D}
{R.struct.MouseInfo}
getMouseInfo()
Get the state of the mouse in the rendering context. You must first enable mouse
event capturing with #captureMouse. See R.struct.MouseInfo for more
information about what is in the object.
- Returns:
- {R.struct.MouseInfo} The current state of the mouse
{HTMLElement}
getSurface()
Get the surface node that all objects will be rendered to.
- Returns:
- {HTMLElement} The document node that represents the rendering surface
{R.struct.TouchInfo}
getTouchInfo()
Get the state of touches in the rendering context. You must first enable touch
event capturing with #captureTouch. See R.struct.TouchInfo for more
information about what is in the object.
- Returns:
- {R.struct.TouchInfo} The current state of touches
{R.math.Rectangle2D}
getViewport()
Get the viewport of the render context.
- Returns:
- {R.math.Rectangle2D}
{R.math.Rectangle2D}
getWorldBoundary(rect)
get the world boundaries.
- Parameters:
- rect
- Returns:
- {R.math.Rectangle2D}
{R.math.Point2D}
getWorldPosition()
Get the world render position.
- Returns:
- {R.math.Point2D}
{Number}
getWorldRotation()
Gets the world rotation angle.
- Returns:
- {Number}
{Array}
getWorldScale()
Gets an array representing the rendering scale of the world.
- Returns:
- {Array} The first element is the X axis, the second is the Y axis
{Boolean}
isStatic()
Determine if the context is static.
- Returns:
- {Boolean}
popTransform()
Decrement the transform stack counter and ensure that the stack
is not unbalanced. An unbalanced stack can be indicative of
objects that do not reset the state after rendering themselves.
pushTransform()
Increment the transform stack counter.
release()
Releases this context back into the pool for reuse
{Object}
remove(obj)
Remove an object from the render context. The object is
not destroyed when it is removed from the container. The removal
occurs after each update to avoid disrupting the flow of object
traversal.
- Parameters:
- obj
- {Object} The object to remove from the container.
- Returns:
- {Object} The object that was removed
{Object}
removeAtIndex(idx)
Remove an object from the render context at the specified index.
The object is not destroyed when it is removed. The removal
occurs after each update to avoid disrupting the flow of object
traversal.
- Parameters:
- idx
- {Number} An index between zero and the size of the container minus 1.
- Returns:
- {Object} The object removed from the container.
render(time, dt)
Called to render all of the objects to the context.
- Parameters:
- time
- {Number} The current world time in milliseconds from the engine.
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
renderObject(obj, time, dt)
Render a single object into the world for the given time.
- Parameters:
- obj
- {R.engine.BaseObject} An object to render
- time
- {Number} The world time, in milliseconds
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
reset(rect)
[ABSTRACT] Clear the context and prepare it for rendering. If you pass a
rectangle, only that portion of the world will be cleared. If
you don't pass a rectangle, the entire context is cleared.
- Parameters:
- rect
- {R.math.Rectangle2D} The area to clear in the context, or null to clear the entire context.
resetTransformStack()
This is a potentially expensive call, and can lead to rendering
errors. It is recommended against calling this method!
setScale(scaleX, scaleY)
[ABSTRACT] Set the scale of the rendering context.
- Parameters:
- scaleX
- {Number} The scale along the X dimension
- scaleY
- {Number} The scale along the Y dimension
setStatic(state)
Set the context to be static. Setting a context to be static effectively removes
it from the automatic update when the world is updated. The user will need to call
#render, passing the world time (gotten with R.Engine#worldTime)
to manually render the context. Any objects within the context will then render
to the context.
- Parameters:
- state
- {Boolean} true to set the context to static
setSurface(element)
Set the surface element that objects will be rendered to.
- Parameters:
- element
- {HTMLElement} The document node that all objects will be rendered to.
setupWorld(time, dt)
[ABSTRACT] Gives the render context a chance to initialize the world.
Use this method to change the world position, rotation, scale, etc.
- Parameters:
- time
- {Number} The current world time
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
setViewport(rect)
Set the viewport of the render context. The viewport is a window
upon the world so that not all of the world is rendered at one time.
- Parameters:
- rect
- {R.math.Rectangle2D} A rectangle defining the viewport
setWorldBoundary(rect)
Set the world boundaries. Set the world boundaries bigger than the viewport
to create a virtual world. By default, the world boundary matches the viewport.
- Parameters:
- rect
- {R.math.Rectangle2D}
setWorldPosition(point, y)
Set the world position of the rendering context. All objects
should be adjuest by this position when the context renders.
- Parameters:
- point
- {R.math.Point2D|Number} The world position or X coordinate
- y Optional
- {Number} If point is a number, this is the Y coordinate
setWorldRotation(rotation)
Set the world rotation of the rendering context. All objects
should be adjusted by this rotation when the context renders.
- Parameters:
- rotation
- {Number} The rotation angle
setWorldScale(scale)
Set the world scale of the rendering context. All objects should
be adjusted by this scale when the context renders.
- Parameters:
- scale
- {Number} The uniform scale of the world
sort(sortFn)
[ABSTRACT] Sort the render context's objects.
- Parameters:
- sortFn
- {Function} A function to sort with, or null to use the default
uncaptureMouse()
Disable mouse event capturing within the render context.
uncaptureTouch()
Disable touch event capturing within the render context.
update(parentContext, time, dt)
Update the render context before rendering the objects to the surface.
If the context isn't static, this will reset and then render the context.
If the context is static, you'll need to perform the reset and render yourself.
This allows you to update objects in the world, skip the reset, and then
render yourself. This can be an effective way to handle redrawing the world
only as needed.
- Parameters:
- parentContext
- {R.rendercontexts.AbstractRenderContext} A parent context, or null
- time
- {Number} The current render time in milliseconds from the engine.
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.