Class Index | File Index

Classes


Class ArcadeJS


Defined in: arcade.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
ArcadeJS(canvas, opts)
A canvas based 2d game engine.
Field Summary
Field Attributes Field Name and Description
 
The augmented HTML <canvas> element.
 
Usable canvas area (defaults to full extent)
 
Position of last mouse click in World Coordinates.
 
Position of last mouse click in Canvas Coordinates.
 
The 2D Rendering Context
<static>  
Default options dictionary.
 
Distance between clickPos and mousePos while dragging in World Coordinates.
 
Distance between clickPos and mousePos while dragging in Canvas Coordinates.
 
Correction factor that will assure constant screen speed when FpS drops.
 
Temporary dictionary to store data during one render loop step.
 
Total number of frames rendered so far.
 
Time elapsed since previous frame in seconds.
 
True if the left mouse button is down.
 
True if the middle mouse button is down.
 
Current mouse position in World Coordinates.
 
Current mouse position in Canvas Coordinates.
 
Game options (ArcadeJS.defaultGameOptions + options passed to the constructor).
 
Frames per second rate that was achieved recently.
 
True if then right mouse button is down.
 
Current time in ticks
 
e.touches recorded at last touch event.
 
Realized viewport (adjusted according to map mode).
 
Viewport map mode ('none', 'extend', 'trim', 'stretch').
 
Requested viewport
Method Summary
Method Attributes Method Name and Description
 
Add game object to object list.
<static>  
ArcadeJS.assert(expression, errorMsg)
Throw error, if expression is `false`.
<static>  
ArcadeJS.assertAttributes(object, attrNames)
Raise error if .
 
debug(msg)
Output string to console.
<static>  
ArcadeJS.explode(s)
Return a string array from a space or comma separated string.
<static>  
ArcadeJS.extendAttributes(object, dict, attrNames)
Copy selected dictionary members as object attributes.
 
Return current activity.
 
Return objects with a given ID or null.
 
getObjectsAtPosition(pt, types, stopOnFirst)
Return an array of objects at a given point.
 
Return an array of objects with a given type (array may be empty).
<static>  
ArcadeJS.guerrillaDerive(target, template, opts)
Copy all entries from `opts` as `target` properties, if there is a matching entry in `template`.
 
isActivity(activities)
Return true, if current activity is in the list.
 
isKeyDown(keyCode)
Return true, if a key is currently pressed.
 
Return true, if render loop is active.
<static>  
ArcadeJS.keyCodeToString(e)
Return a nice string for a keyboard event.
 
later(seconds, callback, data)
Schedule a callback to be triggered after a number of seconds.
 
preCheckCollision(object1, object2)
Wide check if object1 and object2 are collision candiates.
 
purge(force)
Purge dead objects from object list.
 
Reset the usable part of the canvas to full extent.
 
setActivity(activity)
Set current activity and trigger onSetActivity events.
 
setCanvasArea(x, y, width, height, clip)
Define the usable part of the canvas.
 
setDebug(flag)
Enable debug output
 
setViewport(x, y, width, height, mapMode)
Define the visible part of the world.
 
Start render loop.
 
Stop render loop.
 
 
visitObjects(func, types)
Call func(obj) for all objects.
Event Summary
Event Attributes Event Name and Description
 
Called after window was resized.
 
onResize(width, height, e)
Called when window is resized (and on start).
 
onTimeout(data)
Callback, triggered when this.later() timeout expires (and no callback was given).
 
onTouchevent(event, originalEvent)
Called on miscelaneous touch and gesture events.
 
postDraw(ctx)
Called after object.render() was called on all game ojects.
 
Called after all rendering happened and transformations are reset.
 
Called after object.step() was called on all game ojects.
 
preDraw(ctx)
Called before object.render() is called on all game ojects.
 
Called before object.step() is called on all game ojects.
Class Detail
ArcadeJS(canvas, opts)
A canvas based 2d game engine.
Parameters:
{canvas|string} canvas
Canvas element or element id
{object} opts
Game configuration
{string} opts.name Optional
{int} opts.fps Optional, Default: 30
{string} opts.resizeMode Optional, Default: 'adjust'
Adjust internal canvas width/height to match its outer dimensions
{boolean} opts.fullscreenMode Optional, Default: false
Resize canvas to window extensions
{object} opts.fullscreenMargin Optional, Default: {top: 0, right: 0, bottom: 0, left: 0}
{boolean} opts.timeCorrection Optional, Default: true
Adjust object velocities for constant speed when frame rate drops.
{object} opts.debug
Additional debug settings
Field Detail
canvas
The augmented HTML <canvas> element.

canvasArea
Usable canvas area (defaults to full extent)

clickPos
Position of last mouse click in World Coordinates.

clickPosCC
Position of last mouse click in Canvas Coordinates.

context
The 2D Rendering Context

<static> ArcadeJS.defaultGameOptions
Default options dictionary.

dragOffset
Distance between clickPos and mousePos while dragging in World Coordinates.

dragOffsetCC
Distance between clickPos and mousePos while dragging in Canvas Coordinates.

fpsCorrection
Correction factor that will assure constant screen speed when FpS drops.

frameCache
Temporary dictionary to store data during one render loop step.

frameCount
Total number of frames rendered so far.

frameDuration
Time elapsed since previous frame in seconds.

leftButtonDown
True if the left mouse button is down.

middleButtonDown
True if the middle mouse button is down.

mousePos
Current mouse position in World Coordinates.

mousePosCC
Current mouse position in Canvas Coordinates.

opts
Game options (ArcadeJS.defaultGameOptions + options passed to the constructor).

realFps
Frames per second rate that was achieved recently.

rightButtonDown
True if then right mouse button is down.

time
Current time in ticks

touches
e.touches recorded at last touch event.

viewport
Realized viewport (adjusted according to map mode).

viewportMapMode
Viewport map mode ('none', 'extend', 'trim', 'stretch').

viewportOrg
Requested viewport
Method Detail
{Movable} addObject(o)
Add game object to object list.
Parameters:
o
Returns:
{Movable}

<static> ArcadeJS.assert(expression, errorMsg)
Throw error, if expression is `false`.
Parameters:
expression
errorMsg
Throws:
"Assert failed: '...'"

<static> ArcadeJS.assertAttributes(object, attrNames)
Raise error if .
Parameters:
{object} object
or dictionary
{string} attrNames
comma seperated attribute names that will be checked.
Throws:
"Attribute 'x' not found."

debug(msg)
Output string to console.
Parameters:
msg

<static> ArcadeJS.explode(s)
Return a string array from a space or comma separated string.
Parameters:
{string} s
Space or comma separated string.

<static> ArcadeJS.extendAttributes(object, dict, attrNames)
Copy selected dictionary members as object attributes.
Parameters:
{Class} object
dict
{string} attrNames
comma seperated attribute names that will be shallow-copied from dict to object.
Throws:
"Attribute 'x' not found."

{string} getActivity()
Return current activity.
Returns:
{string}

getObjectById(id)
Return objects with a given ID or null.
Parameters:
id

getObjectsAtPosition(pt, types, stopOnFirst)
Return an array of objects at a given point.
Parameters:
pt
types
stopOnFirst

getObjectsByType(types)
Return an array of objects with a given type (array may be empty).
Parameters:
types

<static> ArcadeJS.guerrillaDerive(target, template, opts)
Copy all entries from `opts` as `target` properties, if there is a matching entry in `template`. Note: this is different from `$.extend()`, because only values are copied that are present in `template`. This prevents accidently overriding protected members in `target`. If `temnplate` members have a value of `undefined`, they are mandatory. An exception will be raised, if they are not found in `opts`.
Parameters:
{object} target
Object that will receive the properties (typically `this`).
{object} template
Defines names and default values of all members to copy.
{object} opts
Object with methods and values that override `template` (typically passed to the target constructor).

{boolean} isActivity(activities)
Return true, if current activity is in the list.
Parameters:
{string | string array} activities
Returns:
{boolean}

{boolean} isKeyDown(keyCode)
Return true, if a key is currently pressed.
Parameters:
keyCode
Returns:
{boolean}
See:
Movable.onKeypress

isRunning()
Return true, if render loop is active.
Returns:
Boolean

<static> {string} ArcadeJS.keyCodeToString(e)
Return a nice string for a keyboard event. This function was inspired by progressive.js.
Parameters:
{Event} e
A jQuery event object.
Returns:
{string} 'a' for the key 'a', 'A' for Shift+a, '^a' for Ctrl+a, '[shift]' for

later(seconds, callback, data)
Schedule a callback to be triggered after a number of seconds.
Parameters:
{float} seconds
delay until callback is triggered
{function} callback Optional, Default: this.onTimout
function to be called
{Misc} data Optional
Additional data passed to callback

{boolean} preCheckCollision(object1, object2)
Wide check if object1 and object2 are collision candiates.
Parameters:
object1
object2
Returns:
{boolean}

purge(force)
Purge dead objects from object list.
Parameters:
force

resetCanvasArea()
Reset the usable part of the canvas to full extent.

{string} setActivity(activity)
Set current activity and trigger onSetActivity events.
Parameters:
{string} activity
Returns:
{string} previous activity

setCanvasArea(x, y, width, height, clip)
Define the usable part of the canvas. If set, the viewport is projected into this region. This method should be called on startup and onResize.
Parameters:
{float} x
upper left corner in canvas coordinates
{float} y
upper left corner in canvas coordinates
{float} width
in canvas coordinates
{float} height
in canvas coordinates
{boolean} clip
prevent drawing outside this area (default: true)

setDebug(flag)
Enable debug output
Parameters:
flag

setViewport(x, y, width, height, mapMode)
Define the visible part of the world.
Parameters:
{float} x
lower left corner in world coordinates
{float} y
lower left corner in world coordinates
{float} width
in world coordinate units
{float} height
in world coordinate units
{string} mapMode
'stretch' | 'fit' | 'extend' | 'trim' | 'none'

startLoop()
Start render loop.

stopLoop()
Stop render loop.

toString()

visitObjects(func, types)
Call func(obj) for all objects.
Parameters:
func
types
Event Detail
afterResize(e)
Called after window was resized.
Parameters:
{Event} e

onResize(width, height, e)
Called when window is resized (and on start). The default processing depends on the 'resizeMode' option.
Parameters:
{Int} width
{Int} height
{Event} e
Returns:
false to prevent default handling

onTimeout(data)
Callback, triggered when this.later() timeout expires (and no callback was given).
Parameters:
data
data object passed to this.later()

onTouchevent(event, originalEvent)
Called on miscelaneous touch and gesture events.
Parameters:
{Event} event
jQuery event
{OriginalEvent} originalEvent
depends on mobile device

postDraw(ctx)
Called after object.render() was called on all game ojects.
Parameters:
ctx
Canvas 2D context.

postDrawCC(ctx)
Called after all rendering happened and transformations are reset. Allows accessing the full, untransformed canvas in Canvas Coordinates.
Parameters:
ctx
Canvas 2D context.

postStep()
Called after object.step() was called on all game ojects.

preDraw(ctx)
Called before object.render() is called on all game ojects. object.step() calls have been executed and canvas was cleared.
Parameters:
ctx
Canvas 2D context.

preStep()
Called before object.step() is called on all game ojects.

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Jul 18 2011 14:05:26 GMT+0200 (MESZ)