У меня есть проблема с этим простым прототипирования:JS прототипирования Невозможно установить свойство «moveRight» неопределенных
Game = function (moduleConfig, gameConfig) {
this.moduleConfig = moduleConfig;
this.gameConfig = gameConfig;
// Game-Commands
this.keyCommands = {
moveLeft: false,
moveRight: false
};
this.catcher = null;
this.stage = null;
return this;
}
/**
* Left arrow down
*/
Game.prototype.onKeyboardLeftDown = function() {
this.keyCommands.moveLeft = true;
}
/**
* Left arrow up
*/
Game.prototype.onKeyboardLeftUp = function() {
this.keyCommands.moveLeft = false;
}
Я всегда получаю сообщение об ошибке: Uncaught TypeError: Cannot set property 'moveRight' of undefined
при вызове onKeyboardLeftDown
и onKeyboardLeftUp
. Но я объявил moveLeft
в конструкторе объекта keyCommands
.
Оба метода были названы по ключевым вниз и ключевых вверх событий:
Game.prototype.init = function() {
// ...
// =========================================================================
// Set keyboard
KeyboardJS.on('left', this.onKeyboardLeftDown, this.onKeyboardLeftUp);
KeyboardJS.on('right', this.onKeyboardRightDown, this.onKeyboardRightUp);
// =========================================================================
};
Мой index.html выглядит следующим образом:
<!DOCTYPE html>
<html>
<head>
<title>pixi.js example 1</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #000000;
}
</style>
<script src="js/pixi.dev.js"></script>
<script src="js/keyboard.js"></script>
<script src="js/moduleConfig.js"></script>
<script src="js/moduleResult.js"></script>
<script src="js/game.js"></script>
</head>
<body style="background-color: #EEEEEE">
<script>
var game = new Game(moduleConfig, {
screenWidth: (window.innerWidth - 10),
screenHeight: (window.innerHeight - 10),
bgColor: 0xEEEEEE
});
game.init();
</script>
</body>
</html>
Видит ли кто-нибудь провал? Я много искал, но я очень смущен (обычно я разрабатываю только в C# ...)
Мое предположение: «это» связано с окном? – marko
Почему это связано с окном? – BendEg
Ваша переписка неверна –