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() {
}
}
The above code is my MainGame state code. In create I have created Timer.js object. Now, how to call foo() which is written in Timer.js file. Timer.js is not a state, but just a simple js file.
If instantiating a new variable reference of a class, you can simply call methods on the class from the variable you create.
So in this case, to call method foo()
, simply:
this.timerJS.foo()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.