2 回答

TA貢獻1963條經(jīng)驗 獲得超6個贊
這是this.
你可以用粗箭頭
? ? playbtn.on('click', (event) => {
? ? ? ? this.scene.restart();
? ? });
或者您可以將上下文傳遞給“on”函數(shù),我認為這是查看您的代碼的“游戲”。
? ? playbtn.on('click', function (event) {
? ? ? ? this.scene.restart();
? ? }, game);
這是 Phaser 的文檔中的一個片段on
? ? /**
? ? ?* Add a listener for a given event.
? ? ?* @param event The event name.
? ? ?* @param fn The listener function.
? ? ?* @param context The context to invoke the listener with. Default this.
? ? ?*/
? ? on(event: string | symbol, fn: Function, context?: any): this;

TA貢獻1830條經(jīng)驗 獲得超9個贊
我對 Phaser 不是很熟悉,但this事件處理程序里面可能指的是按鈕。使用粗箭頭將處理函數(shù)綁定到this周圍范圍:
playbtn.on('click', (event) => {
this.scene.restart();
});
添加回答
舉報