-
Notifications
You must be signed in to change notification settings - Fork 2
Cannon
The Cannon main object.
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.
Type: String
Holds the version number of the framework.
Type: String
Holds the name of the framework
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.
Type: Boolean Default: false
Used internally to know if the DOM is already loaded or not.
Type: Array
Contains a list of all registered packages.
- path (String) : path to the file to load
Asks the framework to load a file. The path is relative to the document running the script.
This function is called once all the core classes have been loaded and Cannon is ready to load additional files.
- url (String) : url of the script to load
- callback (Function) : function to call once the script is loaded
Loads a javascript file
An empty function that does nothing, used as the default function internally.
- pack (String) : name of the package
Adds a package and makes it available.
- pack (String) : name of the package
- to (Object) : scope to import the package in. Optionnal, default to window
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.
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
Return the name and the version number of the framework