Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2013-7-29 21:06

Class jaws.SpriteList

Manages all your Sprites in lists. Makes easy mass-draw() / update() possible among others. Implements Array API. "Field Summary" contains options for the SpriteList()-constructor. Sprites (your bullets, aliens, enemies, players etc) will need to be updated, draw, deleted. Often in various orders and based on different conditions. This is where SpriteList() comes in:

Class Summary
Constructor Attributes Constructor Name and Description
 
jaws.SpriteList(options)

Method Summary

Method Attributes Method Name and Description
 
add()
Adds one or more sprites to sprite_list
 
at(index)
Return the sprite at the specified index.
 
Concatenate this sprite list and another array.
 
deleteIf(condition)
Delete sprites in spritelist where condition(sprite) returns true.
 
draw()
Invoke draw() on each element of the sprite list
 
drawIf(condition)
Draw sprites in spritelist where condition(sprite) returns true
 
 
 
 
indexOf(searchElement, fromIndex)
 
Returns true if this object is a sprite lsit.
 
join(separator)
Joins the contents of the sprite list into a string.
 
 
load(objects)
Load sprites into sprite list.
 
map()
 
pop()
 
push()
 
 
 
remove(obj)
Removes the first occurrence of obj from list
 
removeIf(condition)
Remove sprites in spritelist where condition(sprite) returns true
 
 
 
slice(start, end)
 
some()
 
sort()
 
Add or remove sprites from the list.
 
Add one or more sprites to the front of the list
 
Call update() on all sprites in spritelist
 
updateIf(condition)
Call update() on sprites in spritelist where condition(sprite) returns true
 
Update the length of the sprite list.
 

Class Detail

jaws.SpriteList(options)
// create 100 enemies 
var enemies = new SpriteList()
for(i=0; i < 100; i++) { 
  enemies.push(new Sprite({image: "enemy.png", x: i, y: 200}))
}
enemies.draw()                    // calls draw() on all enemies
enemies.update()                  // calls update() on all enemies 
enemies.removeIf(isOutsideCanvas) // removes each item in enemies that returns true when isOutsideCanvas(item) is called
enemies.drawIf(isInsideViewport)  // only call draw() on items that returns true when isInsideViewport is called with item as argument
Parameters:
{Object} options Optional
Currently used to pass in a literal list of sprites. See SpriteList#load for details

Method Detail

  • add()
    Adds one or more sprites to sprite_list
  • {Object} at(index)
    Return the sprite at the specified index. Replaces the array [] notation. So: my_sprite_list.at(1) is equivalent to my_array[1]
    Parameters:
    {Number} index
    Returns:
    {Object} Sprite at index
  • {Object} concat()
    Concatenate this sprite list and another array. Does not modify original.
    Returns:
    {Object} A new SpriteList comprised of this one joined with other lists.
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/concat
  • deleteIf(condition)
    Delete sprites in spritelist where condition(sprite) returns true. Alias for removeIf()
    Parameters:
    condition
  • draw()
    Invoke draw() on each element of the sprite list
  • drawIf(condition)
    Draw sprites in spritelist where condition(sprite) returns true
    Parameters:
    condition
  • {Boolean} every()
    Returns:
    {Boolean}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
  • {Array} filter()
    Returns:
    {Array}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter
  • forEach()
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
  • {Number} indexOf(searchElement, fromIndex)
    Parameters:
    {Object} searchElement
    {Number} fromIndex
    Returns:
    {Number}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
  • {Boolean} isSpriteList()
    Returns true if this object is a sprite lsit. Used to tell SpriteLists and Arrays apart
    Returns:
    {Boolean}
  • join(separator)
    Joins the contents of the sprite list into a string.
    Parameters:
    {String} separator Optional
    String to separate each array element. If ommitted, defaults to comma.
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/join Implemented mostly for an easy verbose way to display the sprites inside the sprite list.
  • lastIndexOf()
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
  • load(objects)
    Load sprites into sprite list. Argument could either be - an array of Sprite objects - an array of JSON objects - a JSON.stringified string representing an array of JSON objects
    Parameters:
    objects
  • {Array} map()
    Returns:
    {Array}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map
  • {Object} pop()
    Returns:
    {Object} Last sprite in the list
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/pop
  • {Number} push()
    Returns:
    {Number} New length of the sprite list
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push
  • {Object|Number|String} reduce()
    Returns:
    {Object|Number|String}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce
  • {Object|Number|String} reduceRight()
    Returns:
    {Object|Number|String}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight
  • remove(obj)
    Removes the first occurrence of obj from list
    Parameters:
    obj
  • removeIf(condition)
    Remove sprites in spritelist where condition(sprite) returns true
    Parameters:
    condition
  • reverse()
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reverse
  • {Object} shift()
    Returns:
    {Object} First sprite in the list
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/shift
  • {Object} slice(start, end)
    Parameters:
    {Number} start
    {Number} end
    Returns:
    {Object} A new array containing sprites (a section of the sprites array defined by start and end)
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/slice
  • {Boolean} some()
    Returns:
    {Boolean}
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
  • sort()
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort
  • {Array} splice()
    Add or remove sprites from the list.
    Returns:
    {Array} Array containing removed sprites
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice
  • {Number} unshift()
    Add one or more sprites to the front of the list
    Returns:
    {Number} New length of the sprite list
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift
  • update()
    Call update() on all sprites in spritelist
  • updateIf(condition)
    Call update() on sprites in spritelist where condition(sprite) returns true
    Parameters:
    condition
  • updateLength()
    Update the length of the sprite list. Since we're delegating array operations to sprites array, this is not done automatically
  • {String} valueOf()
    Returns:
    {String} Literal string representation (currently, just the value of toString() )
    See:
    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/ValueOf