【发布时间】:2015-07-17 17:03:56
【问题描述】:
我有一个这样结构的游戏(删除了一些代码行,但 Browserify 需要所有文件):
游戏需要 boot.js 和 play.js
game.js:
w = window.innerWidth * window.devicePixelRatio,
h = window.innerHeight * window.devicePixelRatio;
window.game = new Phaser.Game((h > w) ? h : w, (h > w) ? w : h, Phaser.CANVAS, 'Phaser', {render:render});
game.state.add('Boot', require('./states/boot.js'));
game.state.add('Play', require('./states/play.js'));
boot.js 启动 play.js
在 boot.js 中:
module.exports = {
preload: function() {
//...
},
create: function() {
game.physics.startSystem(Phaser.Physics.ARCADE);
game.world.setBounds(0, 0, 6000, 6000);
this.game.state.start("Play");
}
};
play.js 需要 interfacePanels.js
在 play.js 中:
chat = require('./../chat.js');
interfacePanels = require('./../interfacePanels.js');
module.exports = {
create: function() {
interfacePanels.init();
},
update: function() {
//....
}
};
interfacePanels.js中有一个方法可以显示玩家的个人资料(这个文件需要profile.js)
代码如下:
profile = require('./profile.js');
module.exports = {
show: function(buttonType) {
switch(buttonType.key) {
case 'menuButtonPress':
break;
case 'profileButtonPress':
if(profile.initialized == false) {
profile.create();
profile.initialized = true;
}
break;
}
}
}
问题出在 profile.js 中:
module.exports = {
initialized: false,
START_X: '',
START_Y: '',
create: function() {
//... some code
},
update: function() {
console.log('profile')
},
};
更新功能根本不起作用。
我可以尝试将更新功能添加到play.js文件中,但是如果我这样做,console.log命令会不会很多?
我需要这个来将元素移动到起点并检查它们是否重叠。
【问题讨论】:
-
任何的功能是否有效?是否加载资产?
create会被调用吗? -
@PhotonStorm,当然。所有功能都运行良好。 “创建”被调用。但是根本不会调用“更新”。
-
@PhotonStorm、Browserify 和 Phaser 在这里协同工作
-
您分享的这几件事似乎没问题,您可能为我们减少了太多代码而无法提供帮助。例如,我们根本看不到“配置文件”模块是如何导入/使用的
-
如果正在调用其他函数,那么这是我们在代码中看不到的。我的猜测是更新被某个地方的另一个函数覆盖,因此你看不到日志。
标签: jquery node.js browserify phaser-framework