[英]Calling Function from another JS file(not a game state) Phaser js
import Timer from '../components/Timer.js';
export default class MainGame extends Phaser.State {
preload() {
console.log("create");
}
create() {
this.timerJS = new Timer(this.game);
}
update() {
}
}
上面的代碼是我的MainGame狀態代碼。 在創建過程中,我創建了Timer.js對象。 現在,如何調用在Timer.js文件中編寫的foo()。 Timer.js不是狀態,而只是一個簡單的js文件。
如果實例化一個類的新變量引用,則可以簡單地從創建的變量中調用該類的方法。
因此,在這種情況下,只需調用方法foo()
即可:
this.timerJS.foo()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.