I am building an event manager for a little game that I am creating and have stumbled on a little problem (I don't know if it is a design pattern problem or if there is a solution to it)!
Take below for example;
o.Events = (function() {
"use strict";
function mousedown() {
// Set mousedown boolean
// # How can I change o.Events.mousedown
// For each layer
this.layers.forEach(function(layer) {
// Layer is listening
if (layer.listening && layer.mouse.x && layer.mouse.y) {
console.log("mousedown");
}
});
};
function init(game) {
// Mousedown boolean
this.mousedown = false;
game.element.addEventListener("mousedown", mousedown.bind(game), false);
};
function Events(game) {
// Initialize events
init.call(this, game);
};
return Events;
})();
How can I change the Events.mousedown
flag even though I am binding game so that inside the function this
is actually game?
Thanks