az-wind
Version:
A library for the exploration of motion in painting
47 lines (38 loc) • 1.13 kB
JavaScript
function PointerManager(ctx) {
var manager = this;
// this is the code that manages all the physics objects
// calls their step functions and their render functions
// make sure to instantiate the manager before creating
// PhysicsPointer objects
this.entities = [];
this.ctx = ctx;
function cleanup() {
manager.entities = manager.entities.filter(function (entity) {
return !entity.dead;
});
}
function step() {
manager.entities.forEach(function(entity) {
if (!entity.dead) {
entity.step();
}
});
cleanup();
requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
PointerManager.prototype.addEntity = function (entity) {
this.entities.push(entity);
};
PointerManager.prototype.setTarget = function (x, y) {
this.entities.forEach(function(entity) {
entity.setTarget(x, y);
});
}
PointerManager.prototype.freeEntities = function () {
this.entities.forEach(function (entity) {
entity.free = true;
});
}
module.exports = PointerManager;