Jump to content

Cordova can't load Phaser


pikminman
 Share

Recommended Posts

Happy new year!

I'm trying to wrap my Phaser game into a Cordova app so I can publish it on the Play Store. It's not working though and I'm tearing what's left of my hair out :(

Here is my HTML code:

<html>
<head>


<script type='text/javascript'>
alert('hi');
</script>

<style>
body {
	margin: 0;
}
</style>
</head>
<body>
<span id='root'></span>
<script type="text/javascript" src="cordova.js"></script>

<!-- I also used the CDN and with/without async defer -->
<script async defer src="./js/phaser.js"></script>

<script async defer src='./js/index.js'></script>
</body>
</html>

  And here is the relevant part of the js:

window.onerror = function(msg, url, linenumber) {
    alert('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+linenumber);
    return true;
}

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

// I tried with and without onDeviceReady()
function onDeviceReady() {
  // All game code here
}

But, when I run it with `cordova build`, and put the APK on my phone, it gives me a reference error. Something along the lines of 'Phaser is not definied'.

I've tried looking for ways to include a library under cordova but no luck. Am I missing something obvious?

 

P.S. It works perfectly in the browser and the alerts do come up in the Cordova build

Link to comment
Share on other sites

Don't use async defer. I know you already tried, but its simpler to start if you don't use it.

Try not to use a dot in the path, use something like src="phaser.js", with the script in the same folder as the html. This way you are certain that the path is correct.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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