Skip to content
y-lohse edited this page Jan 2, 2013 · 9 revisions

The Cannon main object.

Description

The Cannon object holds a few informations for internal use. It also holds references tp all the objects made available by the framework so that they dont leak into the global scope.

Properties

version

Type: String

Holds the version number of the framework.

name

Type: String

Holds the name of the framework

libPath

Type: String Defaukt: Default is empty, but is automatically set to the same directory than the cannon.js file afterwards

Holds the path to the folder containing the other framework files, relative to the document loading the cannon.js file.

readyBound

Type: Boolean Default: false

Used internally to know if the DOM is already loaded or not.

packages

Type: Array

Contains a list of all registered packages.

Functions

include

Parameters

  • path (String) : path to the file to load

Description

Asks the framework to load a file. The path is relative to the document running the script.

__loaded

Description

This function is called once all the core classes have been loaded and Cannon is ready to load additional files.

getScript

Parameters

  • url (String) : url of the script to load
  • callback (Function) : function to call once the script is loaded

Description

Loads a javascript file

v

Description

An empty function that does nothing, used as the default function internally.

registerPackage

Parameters

  • pack (String) : name of the package

Description

Adds a package and makes it available.

use

Parameters

  • pack (String) : name of the package
  • to (Object) : scope to import the package in. Optionnal, default to window

Description

Makes a package or a part of it available inside a given scope. This works in a similar way than the PHP use directive or the actionscript equivalent.

The pack parameter can simply be a name of a package, in which case the whole package is used, or an object inside it. You can use the character ***** as a wildcard.

Examples

Normally, every object in the framework is a child of the Cannon object. In this example, we'll use the Color object.
To use a color, you would need to do this :

Cannon.include('math');
var color = new Cannon.Misc.Color(255, 255, 255);

Once the misc package is used, you can leave simply do :

Cannon.include('math');
Cannon.use('misc');
var color = new Color(255, 255, 255);

Usage of the wildcard :

    Cannon.include('math');
    Cannon.use('*');
    var color = new Color(255, 255, 255);
    //any other object registered inside a package can now be used

You can also scope the wildcards

    Cannon.include('math');
    Cannon.use('Misc.*');
    var color = new Color(255, 255, 255);
    //any other object registered inside the Misc can now be used

Usage of the scope parameter :

    Cannon.include('math');
    var color = new Color(255, 255, 255);//doesn't work

    (function(){
        Cannon.use('*', this);
        var color = new Color(255, 255, 255);//works
    });
    var color = new Color(255, 255, 255);//still doesn't work

toString

Description

Return the name and the version number of the framework