0

我需要帮助让游戏在正确的地方运行,在 onDeviceReady 内。这是我的游戏目前的格式。我不认为游戏运行良好,除非我改变它。主要是我不确定如何确定变量的范围并在设备就绪后设置它们。太感谢了。

var cocoon_active = typeof(Cocoon) === 'object'
var one, two, three; // ...

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
  if (cocoon_active) {
  // ...
  }
  // FIXME CANVAS+ CODE RUNS HERE
}

window.onload = function() {
  game = new Phaser.Game(game_width, game_height, Phaser.AUTO, '');
  game.state.add("play_game", play);
  game.state.start("play_game");
}

var play = function(game){}
play.prototype = {
  preload: function() {},
  create: function() {},
  update: function() {},
  render: function() {}
} // end prototype

function a() {}

function b() {}

function c() {} // ...
4

1 回答 1

0

您是否认为游戏运行不佳,或者您实际上是否遇到错误或黑屏?当您在 CocoonJS 启动器应用程序中尝试时,控制台是否给出任何错误消息?

我在游戏中启动 CocoonJS 之前添加一些代码的方式是这样的。我将以下代码添加到单独的脚本中,并将其作为源代码包含在主 index.html 中:

(function (cocoonjsphaser) {

    cocoonjsphaser.utils = {
        runthisfunction: function () {
            // this code will execute when Cocoon starts
        }
    };
    // etc.
}(window.cocoonjsphaser = window.cocoonjsphaser || {}));

if (navigator.isCocoonJS) {

    // run some code at startup
    cocoonjsphaser.utils.runthisfunction();
}

<body>在主目录中添加了移相器启动代码index.html

<body>
<script>
(function() {
    // initialize the framework
    var game = new Phaser.Game(640, 960, Phaser.AUTO, '');
    // add game states
    game.state.add("play_game", play);
    // game.state.add("level_select", levelselect);
    // game.state.add("main_menu", mainmenu); //etc.
    // start a state
    game.state.start("play_game");
})();
</script>
</body>
于 2016-04-30T18:34:33.797 回答