Class Index | File Index

Classes


Class JSGameSoup

The core jsGameSoup library for entity and event management. You can either pass your own canvas like this: var gs = new JSGameSoup(mycanvas, 30); myGameFunction(gs); gs.launch(); or else when the jsgamesoup.js script is loaded, it will attach a `new JSGameSoup()` instantiation to every canvas tag which has an attribute 'jsgs'. The attribute 'jsgs' specifies the name of the function which should be called to launch the game script associated with that canvas. The 'fps' attribute specifies the desired frame rate of the game engine for that canvas. Once the jsGameSoup engine has been attached to the canvas it starts running immediately. The jsGameSoup engine keeps a list of objects to update and draw every frame. In order to make things happen in your game, you should create objects and add them to the engine with the addEntity() method.
Defined in: jsgamesoup.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
JSGameSoup(canvas, framerate)
Field Summary
Field Attributes Field Name and Description
<inner>  
Array holding all game entities.
 
The number of frames that the app has been running for
 
How fast we are running in FPS
 
The current/last pointer up/down status
 
The current/last position of the pointer
Method Summary
Method Attributes Method Name and Description
 
Add this game entity to our pool of entities (will happen synchronously after update() in the main loop)
 
background(color)
Fill in the background
 
clear the frame.
 
Deletes all entities the engine knows about.
 
Remove this entity from our pool of entities (will happen synchronously after update() in the main loop)
 
distance(a, b)
Returns the distance between two points (two element arrays)
 
This is our main game loop, which gets launched automatically with the launch() method.
 
Gets a list of entities which have already been triggered by the current event.
 
include(url, callback)
Include an external javascript file.
 
Returns true if this entity is in our array of all game entities.
 
Launch an instance of jsGameSoup (generally happens automatically).
 
A null function to assign non-implemented callbacks to.
 
polygon(poly, open)
Draw a polygon
 
random(start, end)
Returns a random real number between start and end.
 
schedule(frames, callback)
Schedule a callback to be run after some number of frames.
 
Call this after any entity's priority changes - it's automatically called when new entities are added.
Class Detail
JSGameSoup(canvas, framerate)
Parameters:
canvas
can be a canvas element object, or the ID of the canvas element which this instance of JSGameSoup should attach itself to. If you pass another type of object, for example a
tag, a canvas of the same size will be created automatically.
framerate
The number of frames per second the game will try to run at on this canvas.
Field Detail
<inner> entities
Array holding all game entities. Use addEntity() and delEntity() to modify it's elements.

frameCount
The number of frames that the app has been running for

framerate
How fast we are running in FPS

pointerDown
The current/last pointer up/down status

pointerPosition
The current/last position of the pointer
Method Detail
addEntity(e)
Add this game entity to our pool of entities (will happen synchronously after update() in the main loop)
Parameters:
e
The entity to be added to the jsGameSoup entity pool.

background(color)
Fill in the background
Parameters:
color
Should be specified like a normal canvas color

clear()
clear the frame. This is called automatically before each frame is drawn.

clearEntities()
Deletes all entities the engine knows about.

delEntity(e)
Remove this entity from our pool of entities (will happen synchronously after update() in the main loop)
Parameters:
e
The entity to be removed from the jsGameSoup entity pool.

distance(a, b)
Returns the distance between two points (two element arrays)
Parameters:
a
The first point.
b
The second point.

gameSoupLoop()
This is our main game loop, which gets launched automatically with the launch() method.

getTriggeredEntities()
Gets a list of entities which have already been triggered by the current event. Call this inside e.g. pointerUp() to get a list of entities which have also had their pointerUp() method called. Note that only lower priority entities will see the triggers of higher priority entities (e.g. entities with higher priorities get triggered first).

include(url, callback)
Include an external javascript file. This is used internally to add functionality from separate files but you can also use it: JSGS.include("myjavascript.js", function(url){ alert(url + 'loaded'); }); Pinched from http://ajaxpatterns.org/On-Demand_Javascript
Parameters:
url
callback

inEntities(e)
Returns true if this entity is in our array of all game entities.
Parameters:
e
The entity which we want to check for in the jsGamesoup entity pool.

launch()
Launch an instance of jsGameSoup (generally happens automatically).

nullfunc()
A null function to assign non-implemented callbacks to.

polygon(poly, open)
Draw a polygon
Parameters:
poly
A list of 2-element lists (x,y) like [[x1, y1,], [x2, y2]...]
open
Whether this polygon is closed or not

random(start, end)
Returns a random real number between start and end. You should use the random.js with seedable random numbers instead.
Parameters:
start
The lower bound of the real number to be chosen.
end
The upper bound of the real number to be chosen.

schedule(frames, callback)
Schedule a callback to be run after some number of frames.
Parameters:
frames
is the number of frames to wait before running this callback. Must be > 1.
callback
is the callback to be run when the given number of frames has elapsed.

sortEntities()
Call this after any entity's priority changes - it's automatically called when new entities are added.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Nov 09 2012 21:19:31 GMT+0800 (WST)