Jump to content

How to change source to run on Cordova/Cocoon's deviceready event?


tidelake
 Share

Recommended Posts

Hello, I learned I have to run the Canvas+ code on deviceready for Cocoon.  I'm not sure how to change my source around to get it right.  Here's how my file is formatted right now.  Somehow I need all the variables scoped into the deviceready event, so I can use the plugins during the game.  Thank you.

 

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() {} // ...

 

Link to comment
Share on other sites

This is what I am using right now for the android status bar plugin:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    StatusBar.hide();
}

After this you can add the rest of your code:

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

 

Link to comment
Share on other sites

I have been doing this, assuming cordova.js is included before your own js code.

 

var startEvent = "DOMContentLoaded";
if(window.cordova){
    startEvent = "deviceready";
}
document.addEventListener(startEvent,function() { 
  // ...
});

This allows the same code to work in and out of a cordova container.

Link to comment
Share on other sites

17 hours ago, tidelake said:

I'm confused. I'm not sure if my game is using the Cavas+ library if my game loads before deviceready.  The dev app console doesn't say "Created Namespace: CanvasPlus" as it does for Webview+ and others.

What do you mean by not being sure? Just wrap your app with Canvas+ or open the project files with Canvas + option from the dev app.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...