我正在查看Phaser遊戲框架,但無法計算出這個關鍵字引用的內容。此關鍵字和遊戲狀態
例如,如果我控制檯登錄'這'它顯示對象MyGame.StateB。但是,如果我用MyGame.StateB替換this關鍵字,例如 MyGame.StateB.background,應用程序拋出一個錯誤。任何人都可以解釋我缺乏理解?
MyGame.StateB = function (game) {
this.background;
this.girls;
};
MyGame.StateB.prototype = {
create: function() {
this.background = this.add.sprite(0, 150, 'background');
this.girls = this.add.sprite(0, 150, 'anizeen');
console.log(this); // MyGame.StateB
var tween = this.add.tween(this.background).to({ x: -800 }, 8000, "Linear", true, 0, -1, true);
}
};
你是怎麼調用'create'函數的? – MinusFour
錯誤說的是什麼?應該幫助你理解......錯誤消息是非常豐富的 – charlietfl
當stateB啓動時(game.state.add('StateB',MyGame.StateB);),調用create函數。錯誤是 - '未捕獲的ReferenceError:在賦值中無效的左手' – stckpete