Namespace: System

System

Source:

Members

<private, static> _caches

Stores references to all items in the system.
Source:

<private, static> _idCount

Used to create unique ids.
Source:

<private, static> _records

Stores references to all items in the system.
Source:

<private, static> _resizeTime :number

Stores the time in milliseconds of the last resize event. Used to pause renderer during resize and resume when resize is complete.
Type:
  • number
Source:

<private, static> _worlds

Stores references to all worlds in the system.
Source:

<static> clock

Increments each time update() is executed.
Source:

<static> mouse

Holds the current and last mouse/touch positions relative to the browser window. Also, holds the current mouse velocity.
Source:

<static> recordData :boolean

Set to true to save properties defined in System.recordItemProperties from each object in each frame.
Type:
  • boolean
Source:

<static> recordedData :Array

Stores properties from each object in each frame.
Type:
  • Array
Source:
Example
 [
    {
      frame: 0,
      items: [
        {},
        {},
        ...
      ]
    }
 ]

<static> recordEndFrame :number

Recording ends with this frame number.
Type:
  • number
Source:

<static> recordItemProperties :Object

Defines the properties to save in System.recordedData for each item in each frame.
Type:
  • Object
Source:

<static> recordStartFrame :number

Recording starts with this frame number.
Type:
  • number
Source:

<static> recordWorldProperties :Object

Defines the properties to save in System.recordedData for each world in each frame.
Type:
  • Object
Source:

<static> supportedFeatures

A map of supported browser features. By default we're assuming support for boxShadows, rgba, and hsla.
Source:

<static> totalFrames :number

Set to a positive number to render only those frames. Leave at -1 to ignore.
Type:
  • number
Source:

<static> trace :boolean

Set to true log flags in a performance tracing tool.
Type:
  • boolean
Source:

Methods

<private, static> _addEvent(target, eventType, The)

Adds an event listener to a DOM element.
Parameters:
Name Type Description
target Object The element to receive the event listener.
eventType string The event type.
The function function to run when the event is triggered.
Source:

<private, static> _addWorld(world)

Adds world to System records and worlds cache.
Parameters:
Name Type Description
world Object A world.
Source:

<private, static> _buildStringHSLA()

Builds an hsla box shadow string based on the passed object's properties.
Source:

<private, static> _buildStringRGBA()

Builds an rgba box shadow string based on the passed object's properties.
Source:

<static> _checkRecordFrame() → {Boolean}

If recordStartFrame and recordEndFrame have been specified, checks if System.clock is within bounds.
Source:
Returns:
True if frame should be recorded.
Type
Boolean

<private, static> _destroyAllItems()

Removes all items in all worlds.
Source:

<private, static> _destroyAllWorlds()

Removes all worlds.
Source:

<private, static> _destroySystem()

Destroys the system.
Source:

<private, static> _keyup(e)

Handles keyup events.
Parameters:
Name Type Description
e Object An event.
Source:

<private, static> _recordMouseLoc()

Saves the mouse/touch location relative to the browser window.
Source:

<private, static> _resetSystem(opt_noRestart=)

Resets the system.
Parameters:
Name Type Description
opt_noRestart= boolean Pass true to not restart the system.
Source:

<private, static> _resize()

Repositions all items relative to the viewport size and resets the world bounds.
Source:

<static> _saveData(index, record)

Saves properties of the passed record that match properties defined in System.recordItemProperties.
Parameters:
Name Type Description
index number The array index for this object.
record Object An Item instance.
Source:

<private, static> _stepForward()

Pauses the system and processes one step in records.
Source:

<private, static> _toggleStats()

Toggles stats display.
Source:

<private, static> _update()

Iterates over objects in the system and calls step() and draw().
Source:

<private, static> _updateCacheLookup(obj, val)

Assigns the given 'val' to the given object's record in System._caches.
Parameters:
Name Type Description
obj Object An object.
val Boolean True if object is active, false if object is destroyed.
Source:

<static> add(klass, opt_options, opt_world)

Adds an item to the system.
Parameters:
Name Type Argument Description
klass string Function will try to create an instance of this class.
opt_options Object <optional>
Object properties.
opt_world string <optional>
The world to contain the item.
Source:

<static> count() → {number}

Returns the total number of items in the system.
Source:
Returns:
Total number of items.
Type
number

<static> destroyItem(obj)

Removes an item from a world.
Parameters:
Name Type Description
obj Object The item to remove.
Source:

<static> extend(subClass, superClass)

Extends the properties and methods of a superClass onto a subClass.
Parameters:
Name Type Description
subClass Object The subClass.
superClass Object The superClass.
Source:

<static> extend() → {Object}

Determines the size of the browser window.
Source:
Returns:
The current browser window width and height.
Type
Object

<static> firstItem() → {Object}

Returns the first item in the system.
Source:
Returns:
An item.
Type
Object

<static> firstWorld() → {null|Object}

Returns the first world in the system.
Source:
Returns:
A world.
Type
null | Object

<static> frameCompleteCallback()

Called if System.totalFrames > -1 and exceeds System.clock.
Source:

<static> getAllBuffers() → {Array.<Buffer>}

Returns all buffers.
Source:
Returns:
An array of buffers.
Type
Array.<Buffer>

<static> getAllItemsByAttribute(attr, opt_val=) → {Array}

Returns an array of items with an attribute that matches the passed 'attr'. If 'opt_val' is passed, 'attr' must equal 'val'.
Parameters:
Name Type Argument Description
attr string The property to match.
opt_val= * <optional>
The 'attr' property must equal 'val'.
Source:
Returns:
An array of items.
Type
Array

<static> getAllItemsByName(name, opt_list) → {Array}

Returns an array of items created from the same constructor.
Parameters:
Name Type Argument Default Description
name string The 'name' property.
opt_list Array <optional>
this._records An optional list of items.
Source:
Returns:
An array of items.
Type
Array

<static> getAllWorlds() → {Array.<World>}

Returns all worlds.
Source:
Returns:
An array of worlds.
Type
Array.<World>

<static> getItem(id) → {Object}

Finds an item by its 'id' and returns it.
Parameters:
Name Type Description
id string | number The item's id.
Source:
Returns:
The item.
Type
Object

<static> getNewId()

Increments idCount and returns the value.
Source:

<static> getRandomNumber(low, high, flt) → {number}

Generates a psuedo-random number within a range.
Parameters:
Name Type Argument Description
low number The low end of the range.
high number The high end of the range.
flt boolean <optional>
Set to true to return a float.
Source:
Returns:
A number.
Type
number

<static> init(opt_setup, opt_worlds, opt_supportedFeatures, opt_noStartLoop)

Initializes the system and starts the update loop.
Parameters:
Name Type Argument Description
opt_setup Function <optional>
Creates the initial system conditions.
opt_worlds Object <optional>
A reference to a DOM element representing the System world.
opt_supportedFeatures Object <optional>
A map of supported browser features.
opt_noStartLoop boolean <optional>
If true, _update is not called. Use to setup a System and start the _update loop at a later time.
Source:

<static> lastItem() → {Object}

Returns the last item in the system.
Source:
Returns:
An item.
Type
Object

<static> lastWorld() → {null|Object}

Returns the last world in the system.
Source:
Returns:
A world.
Type
null | Object

<static> map(value, min1, max1, min2, max2) → {number}

Re-maps a number from one range to another.
Parameters:
Name Type Description
value number The value to be converted.
min1 number Lower bound of the value's current range.
max1 number Upper bound of the value's current range.
min2 number Lower bound of the value's target range.
max2 number Upper bound of the value's target range.
Source:
Returns:
A number.
Type
number

<static> start()

Starts the render loop.
Source:

<static> totalFramesCallback()

Called if System.totalFrames > -1 and exceeds System.clock.
Source:

<static> updateCache(obj)

Adds an object to a cache based on its constructor name.
Parameters:
Name Type Description
obj Object An object. returns {Object} The cache that received the passed object.
Source:

<static> updateItem(item, props) → {Object}

Updates the properties of an item.
Parameters:
Name Type Description
item Object The item.
props Object A map of properties to update.
Source:
Returns:
The item.
Type
Object
Example
System.updateItem(myItem, {
   color: [0, 0, 0],
   scale: 2
}); // item will turn black and double in size

<static> updateItemPropsByName(name, props) → {Array}

Updates the properties of items created from the same constructor.
Parameters:
Name Type Description
name string The constructor name.
props Object A map of properties to update.
Source:
Returns:
An array of items.
Type
Array
Example
System.updateElementPropsByName('point', {
   color: [0, 0, 0],
   scale: 2
}); // all points will turn black and double in size

<static> updateOrientation()

Handles orientation evenst and forces the world to update its bounds.
Source: