Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by failbot

Hi guys.

I'm trying to use Cordova/Phonegap together with ImpactJS. Everything seems to work fine if I use it with iOS/xcode/iPhone/iPad and the cordova framework for that; but I run into problems when trying to do the same thing for Android:

Apparenlty impact prevents cordova from being loaded properly - the 'deviceready' event, that gets fired when cordova is fully loaded[1], never gets fired. Additionally, none of the cordova framework functions are available - for example, I can't use notification to get an alert popup[2].

Keep in mind, that I only have this issue when loading both, impact and cordova at the same time, like so:
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
<script type="text/javascript" charset="utf-8" src="lib/impact/impact.js"></script>
...
<body onload="onLoad()">
...

function onLoad() {
  document.addEventListener('deviceready', onReady, false);
}

/**** This never gets executed ****/
function onReady() {
  console.log("ready");
  navigator.notification.alert("Let's go");


  // code to start the game
}

I've tried different things, changing the loading order, loading the frameworks only the other one was loaded (by injecting <script> into head).
At the moment, I'm using impactjs without the phonegap js functions, but it would be nice if I could use /some/ of the native functions that phones have to offer (vibrating, native notifications, storage, etc.).

Any kind of tips would be apprechiated.

[1] http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#deviceready
[2] http://docs.phonegap.com/en/1.0.0/phonegap_notification_notification.md.html#notification.alert

1 decade ago by failbot

Hi guys.

Alright, I've found a solution that more or less works. It requires modification of impact.js though:

Loader for impact. This loads the impact lib after the deviceready event was fired (and Cordova was fully loaded).

function onDOMReady() {
	document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
	loadImpact();
}

function loadImpact() {
	var scripts = ['lib/impact/impact.js','lib/game/main.js'];
	for (var i = 0; i < scripts.length; ++i) {
		var script_element = document.createElement('script');
		script_element.setAttribute('type', 'text/javascript');
		script_element.setAttribute('charset', 'utf-8');
		script_element.setAttribute('src', scripts[i]);
			
		document.getElementsByTagName('body')[0].appendChild(script_element);
	}
}

<body onload="onDOMReady()">

I modified lib/impact.js:
Line 447 (before the ig.module call)


/* Cordova "PATCH" */

/* Check if impact is loaded after DOM is already complete. If that's the case, we don't need to
 * wait for the dom.ready "event" */

if (document.readyState === 'complete') {
	ig.modules['dom.ready'] = { requires: [], loaded: true, body: null };
}
/* Cordova "PATCH" END */

ig.module(
	'impact.impact'
)


This solves the following error when loading impactjs with the routine above:
uncaught exception: Unresolved (circular?) dependencies. Most likely there's a name/path mismatch for one of the listed modules: impact.impact (requires: )
uncaught exception: Module 'impact.impact' defines nothing

Remember to NOT include the impact.js and main.js in your <head>; this is done by the loadImpact() function after the page has fully loaded.

1 decade ago by failbot

Note: This issue is resolved in impactjs 1.20.
You do not need the preloader or the fix anymore - you can include both cordiva and impactjs in <head>.
Page 1 of 1
« first « previous next › last »