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 文件。
如果实例化一个类的新变量引用,您可以简单地从您创建的变量调用该类的方法。
所以在这种情况下,要调用 method foo()
,只需:
this.timerJS.foo()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句