Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2013-3-5 0:35

Namespace jaws

JawsJS core functions. "Field Summary" contains readable properties on the main jaws-object.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Field Summary
Field Attributes Field Name and Description
 
The detected/created canvas-element used for the game
 
The detected/created canvas 2D-context, used for all draw-operations
 
Height of the canvas-element
 
Mouse X position with respect to the canvas-element
 
Mouse Y position with respect to the canvas-element
 
Width of the canvas-element

Method Summary

Method Attributes Method Name and Description
<static>  
jaws.clear()
Clears screen (the canvas-element) through context.clearRect()
<static>  
jaws.collideCircles(object1, object2)
Returns true if circles collide.
<static>  
jaws.collideManyWithMany(list1, list2)
Collides two list/arrays of objects -- 'list1' and 'list2'.
<static>  
jaws.collideOneWithMany(object, list)
collide one single object 'object' with a list of objects 'list'.
<static>  
jaws.collideOneWithOne(object1, object2)
collides 2 single objects by reading x, y and either method rect() or property radius.
<static>  
jaws.collideRects(rect1, rect2)
Returns true if 'rect1' collides with 'rect2'
<inner>  
combinations(list, n)
private
<static>  
jaws.distanceBetween(object1, object2)
returns the distance between 2 objects
<static>  
jaws.forceArray(obj)
Return obj as an array.
<static>  
jaws.forceInsideCanvas(item)
Force item inside canvas by setting items x/y parameters item needs to have the properties x, y, width & height
<static>  
Return a hash of url-parameters and their values
<static>  
jaws.imageToCanvas(image)
Takes an image, returns a canvas-element containing that image.
<static>  
jaws.isArray(obj)
Returns true if obj is an Array
<static>  
jaws.isCanvas(obj)
Returns true of obj is a Canvas-element
<static>  
jaws.isDrawable(obj)
Returns true of obj is either an Image or a Canvas-element
<static>  
jaws.isFunction(obj)
Returns true of obj is a Function
<static>  
jaws.isImage(obj)
Returns true if obj is an Image
<static>  
jaws.isOutsideCanvas(item)
Returns true if item is outside the canvas.
<static>  
jaws.isString(obj)
Returns true if obj is a String
<static>  
jaws.log(msg, append)
Logs msg to previously found or created
if append is true, append rather than overwrite the last log-msg.
<static>  
jaws.on_keydown(key, callback)
sets up a callback for a key (or array of keys) to call when it's pressed down
<static>  
jaws.on_keyup(key, callback)
sets up a callback when a key (or array of keys) to call when it's released
<static>  
jaws.parseOptions(object, options, defaults)
Check for bad options/catch typos and init object with defaults options.
<static>  
jaws.pressed(key)
Returns true if *key* is currently pressed down
<static>  
jaws.preventDefaultKeys(array_of_strings)
Prevents default browseraction for given keys.
<static>  
jaws.start(game_state, options, game_state_setup_options)
Quick and easy startup of a jaws game loop.
<static>  
jaws.switchGameState(game_state, options, game_state_setup_options)
Switch to a new active game state Save previous game state in jaws.previous_game_state
<static>  
jaws.unpack()
Unpacks Jaws core-constructors into the global namespace.

Namespace Detail

jaws
Jaws, a HTML5 canvas/javascript 2D game development framework

Homepage:      http://jawsjs.com/
Source:        http://github.com/ippa/jaws/
Documentation: http://jawsjs.com/docs/

Works with:  Chrome 6.0+, Firefox 3.6+, 4+, IE 9+
License: LGPL - http://www.gnu.org/licenses/lgpl.html

Jaws uses the "module pattern". 
Adds 1 global, jaws, so plays nice with all other JS libs.
 
Formating guide:
  jaws.oneFunction()
  jaws.one_variable = 1
  new jaws.OneConstructor

Have fun! 

ippa.
Parameters:
jaws

Field Detail

{canvas} canvas
The detected/created canvas-element used for the game
{context} context
The detected/created canvas 2D-context, used for all draw-operations
{int} height
Height of the canvas-element
{int} mouse_x
Mouse X position with respect to the canvas-element
{int} mouse_y
Mouse Y position with respect to the canvas-element
{int} width
Width of the canvas-element

Method Detail

  • <static> jaws.clear()
    Clears screen (the canvas-element) through context.clearRect()
  • <static> jaws.collideCircles(object1, object2)
    Returns true if circles collide. Takes two objects with properties "radius" as argument.
    Defined in: collision_detection.js.
    Parameters:
    object1
    object2
  • <static> jaws.collideManyWithMany(list1, list2)
    Collides two list/arrays of objects -- 'list1' and 'list2'. Returns an array of arrays with colliding pairs from 'list1' and 'list2'. Will never collide objects with themselves, even if you collide the same list with itself.
    Defined in: collision_detection.js.
      jaws.collideManyWithMany(bullets, enemies) // --> [[bullet, enemy], [bullet, enemy]]
    Parameters:
    list1
    list2
  • <static> jaws.collideOneWithMany(object, list)
    collide one single object 'object' with a list of objects 'list'. returns an array of items from 'list' that collided with 'object'. returns empty array of no collisions are found. will never collide objects with themselves.
    Defined in: collision_detection.js.
    Parameters:
    object
    list
  • <static> jaws.collideOneWithOne(object1, object2)
    collides 2 single objects by reading x, y and either method rect() or property radius. returns true if the two objects are colliding.
    Defined in: collision_detection.js.
    Parameters:
    object1
    object2
  • <static> jaws.collideRects(rect1, rect2)
    Returns true if 'rect1' collides with 'rect2'
    Defined in: collision_detection.js.
    Parameters:
    rect1
    rect2
  • <inner> combinations(list, n)
    private
    Defined in: collision_detection.js.
    Parameters:
    list
    n
  • <static> jaws.distanceBetween(object1, object2)
    returns the distance between 2 objects
    Defined in: collision_detection.js.
    Parameters:
    object1
    object2
  • <static> jaws.forceArray(obj)
    Return obj as an array. An array is returned as is. This is useful when you want to iterate over an unknown variable.
      jaws.forceArray(1)       // --> [1]
      jaws.forceArray([1,2])   // --> [1,2]
    Parameters:
    obj
  • <static> jaws.forceInsideCanvas(item)
    Force item inside canvas by setting items x/y parameters item needs to have the properties x, y, width & height
    Parameters:
    item
  • <static> jaws.getUrlParameters()
    Return a hash of url-parameters and their values
      // Given the current URL is http://test.com/?debug=1&foo=bar
      jaws.getUrlParameters() // --> {debug: 1, foo: bar}
  • <static> jaws.imageToCanvas(image)
    Takes an image, returns a canvas-element containing that image. Benchmarks has proven canvas to be faster to work with then images in certain browsers. Returns: a canvas-element
    Parameters:
    image
  • <static> jaws.isArray(obj)
    Returns true if obj is an Array
    Parameters:
    obj
  • <static> jaws.isCanvas(obj)
    Returns true of obj is a Canvas-element
    Parameters:
    obj
  • <static> jaws.isDrawable(obj)
    Returns true of obj is either an Image or a Canvas-element
    Parameters:
    obj
  • <static> jaws.isFunction(obj)
    Returns true of obj is a Function
    Parameters:
    obj
  • <static> jaws.isImage(obj)
    Returns true if obj is an Image
    Parameters:
    obj
  • <static> jaws.isOutsideCanvas(item)
    Returns true if item is outside the canvas. item needs to have the properties x, y, width & height
    Parameters:
    item
  • <static> jaws.isString(obj)
    Returns true if obj is a String
    Parameters:
    obj
  • <static> jaws.log(msg, append)
    Logs msg to previously found or created
    if append is true, append rather than overwrite the last log-msg.
    Parameters:
    msg
    append
  • <static> jaws.on_keydown(key, callback)
    sets up a callback for a key (or array of keys) to call when it's pressed down
    Defined in: input.js.
    // call goLeft() when left arrow key is  pressed
    jaws.on_keypress("left", goLeft) 
    
    // call fireWeapon() when SPACE or CTRL is pressed
    jaws.on_keypress(["space","ctrl"], fireWeapon)
    Parameters:
    key
    callback
  • <static> jaws.on_keyup(key, callback)
    sets up a callback when a key (or array of keys) to call when it's released
    Defined in: input.js.
    Parameters:
    key
    callback
  • <static> jaws.parseOptions(object, options, defaults)
    Check for bad options/catch typos and init object with defaults options. Used in all major constructors like Sprite() and so on.
    Parameters:
    object
    options
    defaults
  • <static> jaws.pressed(key)
    Returns true if *key* is currently pressed down
    Defined in: input.js.
    jaws.pressed("left");  // returns true if arrow key is pressed
    jaws.pressed("a");     // returns true if key "a" is pressed
    Parameters:
    key
  • <static> jaws.preventDefaultKeys(array_of_strings)
    Prevents default browseraction for given keys.
    Defined in: input.js.
    jaws.preventDefaultKeys( ["down"] )  // Stop down-arrow-key from scrolling page down
    Parameters:
    array_of_strings
  • <static> jaws.start(game_state, options, game_state_setup_options)
    Quick and easy startup of a jaws game loop.
     // jaws.start(YourGameState) It will do the following:
     //
     // 1) Call jaws.init() that will detect any canvas-tag (or create one for you) and set up the 2D context, then available in jaws.canvas and jaws.context.
     //
     // 2) Pre-load all defined assets with jaws.assets.loadAll() while showing progress, then available in jaws.assets.get("your_asset.png").
     //
     // 3) Create an instance of YourGameState() and call setup() on that instance. In setup() you usually create your gameobjects, sprites and so on.
     // 
     // 4) Loop calls to update() and draw() with given FPS (default 60) until game ends or another game state is activated.
    
    
     jaws.start(MyGame)            // Start game state Game() with default options
     jaws.start(MyGame, {fps: 30}) // Start game state Geme() with options, in this case jaws will run your game with 30 frames per second.
     jaws.start(window)            // Use global functions setup(), update() and draw() if available. Not the recommended way but useful for testing and mini-games.
    
     // It's recommended not giving fps-option to jaws.start since then it will default to 60 FPS and using requestAnimationFrame when possible.
    Parameters:
    game_state
    options
    game_state_setup_options
  • <static> jaws.switchGameState(game_state, options, game_state_setup_options)
    Switch to a new active game state Save previous game state in jaws.previous_game_state
    function MenuState() {
      this.setup = function() { ... }
      this.draw = function() { ... }
      this.update = function() {
        if(pressed("enter")) jaws.switchGameState(GameState); // Start game when Enter is pressed
      }
    }
    
    function GameState() {
      this.setup = function() { ... }
      this.update = function() { ... }
      this.draw = function() { ... }
    }
    
    jaws.start(MenuState)
    Parameters:
    game_state
    options
    game_state_setup_options
  • <static> jaws.unpack()
    Unpacks Jaws core-constructors into the global namespace. If a global property is allready taken, a warning will be written to jaws log. After calling jaws.unpack() you can use Sprite() instead of jaws.Sprite(), Animation() instead of jaws.Animation() and so on.