using that instead of this -> fixing scope problems
This commit is contained in:
parent
caac063806
commit
3818496faa
3 changed files with 23 additions and 22 deletions
|
@ -1,7 +1,8 @@
|
|||
var DisplayController = function() {
|
||||
var that = {};
|
||||
|
||||
|
||||
this.draw = function() {
|
||||
|
||||
that.draw = function() {
|
||||
console.log("draw");
|
||||
};
|
||||
return that;
|
||||
};
|
|
@ -1,26 +1,25 @@
|
|||
var GameController = function(inputController, displayController) {
|
||||
var that = {};
|
||||
that._loopRunning = false;
|
||||
that._loop = null;
|
||||
that._inputController = inputController;
|
||||
that._displayController = displayController;
|
||||
|
||||
this._loopRunning = false;
|
||||
this._loop = null;
|
||||
this._inputController = inputController;
|
||||
this._displayController = displayController;
|
||||
|
||||
this.start = function() {
|
||||
this._loopRunning = true;
|
||||
this._loop = setInterval(this.loop, 30);
|
||||
that.start = function() {
|
||||
that._loopRunning = true;
|
||||
that._loop = setInterval(that.loop, 30);
|
||||
};
|
||||
|
||||
this.stop = function() {
|
||||
this._loopRunning = false;
|
||||
that.stop = function() {
|
||||
that._loopRunning = false;
|
||||
};
|
||||
|
||||
this.loop = function() {
|
||||
this._inputController.observe();
|
||||
|
||||
that.loop = function() {
|
||||
that._inputController.observe();
|
||||
// add other stuff here
|
||||
|
||||
this._displayController.draw();
|
||||
that._displayController.draw();
|
||||
};
|
||||
|
||||
|
||||
|
||||
return that;
|
||||
};
|
|
@ -1,7 +1,8 @@
|
|||
var InputController = function() {
|
||||
|
||||
var that = {};
|
||||
|
||||
this.observe = function() {
|
||||
|
||||
that.observe = function() {
|
||||
console.log("input");
|
||||
};
|
||||
return that;
|
||||
};
|
Loading…
Reference in a new issue