Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2013-9-6 21:36

Namespace jaws

JawsJS core functions. 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

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.clone(value)
Returns a shallow copy of an array or object
<static>  
jaws.collide(x, x2, callback)
Compares two objects or lists, returning if they collide, and calling 'callback' per collision (if set) between objects or lists.
<static>  
jaws.collideCircles(object1, object2)
Returns if two circle-objects collide with each other
<static>  
jaws.collideManyWithMany(list1, list2, callback)
Compares two lists, returning those items from each that collide with each other, and calling 'callback' per collision (if set) with item from list1 and item from list2.
<static>  
jaws.collideOneWithMany(object, list, callback)
Compares an object against a list, returning those from list that collide with object, and calling 'callback' per collision (if set) with object and item from list.
<static>  
jaws.collideOneWithOne(object1, object2)
Collides two objects by reading x, y and either method rect() or property radius.
<static>  
jaws.collideRects(rect1, rect2)
Returns if two Rects collide with each other or not
<static>  
jaws.distanceBetween(object1, object2)
Returns the distance between two objects
<static>  
jaws.draw()
calls draw() on everything you throw on it.
<static>  
jaws.fill(fill_style)
Fills the screen with given fill_style
<static>  
jaws.forceArray(obj)
Returns object as an array
<static>  
jaws.forceInsideCanvas(item)
Sets x and y properties to 0 (if less than), or jaws.width or jaws.height (if greater than)
<static>  
Parses current window.location for URL parameters and values
<static>  
jaws.imageToCanvas(image)
Creates a new HTMLCanvasElement from a HTMLImageElement
<static>  
jaws.isArray(obj)
Tests if an object is an Array or not
<static>  
jaws.isCanvas(obj)
Tests if object is a Canvas object
<static>  
jaws.isDrawable(obj)
Tests if an object is either a canvas or an image object
<static>  
jaws.isFunction(obj)
Tests if an object is a function or not
<static>  
jaws.isImage(obj)
Tests if object is an image or not
<static>  
jaws.isNumber(n)
Tests if an object is a number or not
<static>  
jaws.isObject(value)
Tests if an object is an Object or not
<static>  
jaws.isOutsideCanvas(item)
Tests if an object is within drawing canvas (jaws.width and jaws.height)
<static>  
jaws.isRegExp(obj)
Tests if an object is a regular expression or not
<static>  
jaws.isString(obj)
Tests if an object is a string or not
<static>  
jaws.log(msg, append)
Writes messages to either log_tag (if set) or console.log (if available)
<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)
Compares an object's default properties against those sent to its constructor
<static>  
jaws.pressed(keys, logical_and)
Check if *keys* are pressed.
<static>  
jaws.pressedWithoutRepeat(keys, logical_and)
Check if *keys* are pressed, but only return true Once for any given keys.
<static>  
jaws.preventDefaultKeys(array_of_strings)
Prevents default browseraction for given keys.
<static>  
jaws.retroScaleImage(image, factor)
scale 'image' by factor 'factor'.
<static>  
jaws.start(game_state, options, game_state_setup_options)
1) Calls jaws.init(), detects or creats a canvas, and sets up the 2D context (jaws.canvas and jaws.context).
<static>  
jaws.switchGameState(game_state, options, game_state_setup_options)
Switchs to a new active game state and saves previous game state in jaws.previous_game_state
<static>  
jaws.unpack()
Unpacks Jaws core-constructors into the global namespace.
<static>  
jaws.update()
calls update() on everything you throw on it.
<static>  
Use 'retro' crisp scaling when drawing sprites through the canvas API, this is the default
<static>  
Use smooth antialiased scaling when drawing sprites through the canvas API

Namespace Detail

jaws
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> {array|object} jaws.clone(value)
    Returns a shallow copy of an array or object
    Parameters:
    {array|object} value
    The array or object to clone
    Returns:
    {array|object} A copy of an array of object
  • <static> {boolean} jaws.collide(x, x2, callback)
    Compares two objects or lists, returning if they collide, and calling 'callback' per collision (if set) between objects or lists.
    Defined in: collision_detection.js.
    Parameters:
    {array|object} x
    An object with either 'rect' or 'forEach' property
    {array|object} x2
    An object with either 'rect' or 'forEach' property
    {function} callback
    Returns:
    {boolean}
  • <static> {boolean} jaws.collideCircles(object1, object2)
    Returns if two circle-objects collide with each other
    Defined in: collision_detection.js.
    Parameters:
    {object} object1
    An object with a 'radius' property
    {object} object2
    An object with a 'radius' property
    Returns:
    {boolean} If two circle-objects collide or not
  • <static> {array} jaws.collideManyWithMany(list1, list2, callback)
    Compares two lists, returning those items from each that collide with each other, and calling 'callback' per collision (if set) with item from list1 and item from list2. (Note: Will never collide objects with themselves.)
    Defined in: collision_detection.js.
     jaws.collideManyWithMany(bullets, enemies) // --> [[bullet, enemy], [bullet, enemy]]
    Parameters:
    {array|object} list1
    A collection of objects with a 'forEach' property
    {array|object} list2
    A collection of objects with a 'forEach' property
    {function} callback
    The function to be called per collison detected
    Returns:
    {array} A collection of items colliding with list1 from list2
  • <static> {array} jaws.collideOneWithMany(object, list, callback)
    Compares an object against a list, returning those from list that collide with object, and calling 'callback' per collision (if set) with object and item from list. (Note: Will never collide objects with themselves.)
    Defined in: collision_detection.js.
    collideOneWithMany(player, bullets)    // -> [bullet1, bullet1]
    collideOneWithMany(player, bullets, function(player, bullet) {
     //player and bullet (bullets[i])
    });
    Parameters:
    {object} object
    An object with a 'radius' or 'rect' property
    {array|object} list
    A collection of objects with a 'length' property
    {function} callback
    The function to be called per collison detected
    Returns:
    {array} A collection of items colliding with object from list
  • <static> {boolean} jaws.collideOneWithOne(object1, object2)
    Collides two objects by reading x, y and either method rect() or property radius.
    Defined in: collision_detection.js.
    Parameters:
    {object} object1
    An object with a 'radius' or 'rect' property
    {object} object2
    An object with a 'radius' or 'rect' property
    Returns:
    {boolean} If the two objects are colliding or not
  • <static> {boolean} jaws.collideRects(rect1, rect2)
    Returns if two Rects collide with each other or not
    Defined in: collision_detection.js.
    Parameters:
    {object} rect1
    An object with 'x', 'y', 'right' and 'bottom' properties
    {object} rect2
    An object with 'x', 'y', 'right' and 'bottom' properties
    Returns:
    {boolean} If two Rects collide with each other or not
  • <static> {number} jaws.distanceBetween(object1, object2)
    Returns the distance between two objects
    Defined in: collision_detection.js.
    Parameters:
    {object} object1
    An object with 'x' and 'y' properties
    {object} object2
    An object with 'x' and 'y' properties
    Returns:
    {number} The distance between two objects
  • <static> jaws.draw()
    calls draw() on everything you throw on it. Give it arrays, argumentlists, arrays of arrays.
  • <static> jaws.fill(fill_style)
    Fills the screen with given fill_style
    Parameters:
    fill_style
  • <static> {array} jaws.forceArray(obj)
    Returns object as an array
      jaws.forceArray(1)       // --> [1]
      jaws.forceArray([1,2])   // --> [1,2]
    Parameters:
    {object} obj
    An array or object
    Returns:
    {array} Either an array or the object as an array
  • <static> jaws.forceInsideCanvas(item)
    Sets x and y properties to 0 (if less than), or jaws.width or jaws.height (if greater than)
    Parameters:
    {object} item
    An object with x and y properties
  • <static> {array} jaws.getUrlParameters()
    Parses current window.location for URL parameters and values
      // Given the current URL is http://test.com/?debug=1&foo=bar
      jaws.getUrlParameters() // --> {debug: 1, foo: bar}
    Returns:
    {array} Hash of url-parameters and their values
  • <static> {HTMLCanvasElement} jaws.imageToCanvas(image)
    Creates a new HTMLCanvasElement from a HTMLImageElement
    Parameters:
    {HTMLImageElement} image
    The HTMLImageElement to convert to a HTMLCanvasElement
    Returns:
    {HTMLCanvasElement} A HTMLCanvasElement with drawn HTMLImageElement content
  • <static> {boolean} jaws.isArray(obj)
    Tests if an object is an Array or not
    Parameters:
    {object} obj
    An array or array-like object
    Returns:
    {boolean} If object's constructor is "Array"
  • <static> {boolean} jaws.isCanvas(obj)
    Tests if object is a Canvas object
    Parameters:
    {type} obj
    A canvas or canvas-like object
    Returns:
    {boolean} If object's prototype is "HTMLCanvasElement"
  • <static> {boolean} jaws.isDrawable(obj)
    Tests if an object is either a canvas or an image object
    Parameters:
    {object} obj
    A canvas or canva-like object
    Returns:
    {boolean} If object isImage or isCanvas
  • <static> {boolean} jaws.isFunction(obj)
    Tests if an object is a function or not
    Parameters:
    {object} obj
    A function or function-like object
    Returns:
    {boolean} If the prototype of the object is "Function"
  • <static> {boolean} jaws.isImage(obj)
    Tests if object is an image or not
    Parameters:
    {object} obj
    An Image or image-like object
    Returns:
    {boolean} If object's prototype is "HTMLImageElement"
  • <static> {boolean} jaws.isNumber(n)
    Tests if an object is a number or not
    Parameters:
    {number} n
    A number or number-like value
    Returns:
    {boolean} If n passed isNaN() and isFinite()
  • <static> {boolean} jaws.isObject(value)
    Tests if an object is an Object or not
    Parameters:
    {object} value
    An object or object-like enitity
    Returns:
    {boolean} If object is not null and typeof 'object'
  • <static> {boolean} jaws.isOutsideCanvas(item)
    Tests if an object is within drawing canvas (jaws.width and jaws.height)
    Parameters:
    {object} item
    An object with both x and y properties
    Returns:
    {boolean} If the item's x and y are less than 0 or more than jaws.width or jaws.height
  • <static> {boolean} jaws.isRegExp(obj)
    Tests if an object is a regular expression or not
    Parameters:
    {object} obj
    A /regexp/-object
    Returns:
    {boolean} If the object is an instance of RegExp
  • <static> {boolean} jaws.isString(obj)
    Tests if an object is a string or not
    Parameters:
    {object} obj
    A string or string-like object
    Returns:
    {boolean} The result of typeof and constructor testing
  • <static> jaws.log(msg, append)
    Writes messages to either log_tag (if set) or console.log (if available)
    Parameters:
    {string} msg
    The string to write
    {boolean} append
    If messages should be appended or not
  • <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)
    Compares an object's default properties against those sent to its constructor
    Parameters:
    {object} object
    The object to compare and assign new values
    {object} options
    Object-literal of constructor properties and new values
    {object} defaults
    Object-literal of properties and their default values
  • <static> jaws.pressed(keys, logical_and)
    Check if *keys* are pressed. Second argument specifies use of logical AND when checking multiple keys.
    Defined in: input.js.
    jaws.pressed("left a");          // returns true if left arrow key OR a is pressed
    jaws.pressed("ctrl c", true);    // returns true if ctrl AND a is pressed
    Parameters:
    keys
    logical_and
  • <static> jaws.pressedWithoutRepeat(keys, logical_and)
    Check if *keys* are pressed, but only return true Once for any given keys. Once keys have been released, pressedWithoutRepeat can return true again when keys are pressed. Second argument specifies use of logical AND when checking multiple keys.
    Defined in: input.js.
    if(jaws.pressedWithoutRepeat("space")) { player.jump() }  // with this in the gameloop player will only jump once even if space is held down
    Parameters:
    keys
    logical_and
  • <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.retroScaleImage(image, factor)
    scale 'image' by factor 'factor'. Scaling is done using nearest-neighbor ( retro-blocky-style ). Returns a canvas.
    Parameters:
    image
    factor
  • <static> jaws.start(game_state, options, game_state_setup_options)
    1) Calls jaws.init(), detects or creats a canvas, and sets up the 2D context (jaws.canvas and jaws.context). 2) Pre-loads all defined assets with jaws.assets.loadAll(). 3) Creates an instance of game_state and calls setup() on that instance. 4) Loops calls to update() and draw() with given FPS 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 Game() 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.
    Parameters:
    {function} game_state
    The game state function to be started
    {object} options
    Object-literal of game loop properties
    {object} game_state_setup_options
    Object-literal of game state properties and values
    See:
    jaws.init()
    jaws.setupInput()
    jaws.assets.loadAll()
    jaws.switchGameState()
  • <static> jaws.switchGameState(game_state, options, game_state_setup_options)
    Switchs to a new active game state and saves 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:
    {function} game_state
    The game state function to start
    {object} options
    The object-literal properties to pass to the new game loop
    {object} game_state_setup_options
    The object-literal properties to pass to starting game state
  • <static> jaws.unpack()
    Unpacks Jaws core-constructors into the global namespace. If a global property is already taken, a warning will be written to jaws log.
  • <static> jaws.update()
    calls update() on everything you throw on it. Give it arrays, argumentlists, arrays of arrays.
  • <static> jaws.useCrispScaling()
    Use 'retro' crisp scaling when drawing sprites through the canvas API, this is the default
  • <static> jaws.useSmoothScaling()
    Use smooth antialiased scaling when drawing sprites through the canvas API