Game Development Reference
In-Depth Information
// Make this function empty by default, and
allow the user tooverride it
var update = function(){};
// Add a component to this entity if one by
this name has notyet been added
function addComponent(key, component) {
if (!components[key]) {
components[key] = component;
}
return component;
}
// Attempt to remove an entity by its name
function removeComponent(key) {
if (components[key]) {
return delete components[key];
}
return false;
}
// Return a reference to a component
function getComponent(key) {
return components[key] || null;
}
// Draw this component
function draw() {
if (components.sprite) {
components.sprite.update();
}
}
// Expose these functions through a public
interface
Search WWH ::




Custom Search