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 Hazneliel

I was studying this function from the BioLab game:

BiolabGame.start = function() { ... }

It starts the game with different settings depending on the device. What I cannot understand is how is that function, and where it is called from.

In my application I replaced this line:

ig.main('#canvas', TitleScreen, 60, 160, 208, 2 * ig.ua.pixelRatio);

with the MyGame.start = function() { ... }

but it is never called, The canvas doesnt draw anything and I dont see any erros in the console. Could someone explain to me how do this works?

Thank you

1 decade ago by dominic

The start function for Biolab is called from the .html file.

This is specifically done for the mobile version of the game, where I don't want to start the game immediately after the .js files have been loaded, but only after an advertisement is shown and the user clicked on the "start game" button. It's just a "proxy" for ig.main.

Have a look at the source of this html page:
http://playbiolab.com/index-mobile.html

<script type="text/javascript">
	function startgame() {
		
		// This hides the advertisement, shows the canvas 
		// and prevents scrolling
		document.getElementById('ad').style.display = 'none';
		document.getElementById('game').style.display = 'block';
		document.body.addEventListener('touchmove', function(e) { 
			e.preventDefault(); 
			window.scrollTo(0,1); 
		},false);
		
		// I define another module here, that requires my main game 
		// module (typically game.main instead of biolab.biolab) to 
		// make sure it's completely loaded.
		// If you bake your game into one .js file, you don't need 
		// to do this, though
		ig.module('main').requires('biolab.biolab').defines(function(){
			
			// Call my start() funtcion, that will in turn call ig.main
			BiolabGame.start();
			
			window.scrollTo(0,1);
		});
		return false;
	}
</script>

The startgame() function defined above is then called when the user clicks the Play Biolab Disaster button:

<a href="#" id="play" onclick="return startgame();">Play Biolab Disaster!</a>

If you just want to start the game as soon as the .js files are loaded, you don't need a separate "start" function. You can still call ig.main with different settings with some if statements near the end of you main.js. E.g.
if( ig.ua.mobile ) {
	ig.Sound.enabled = false;
	ig.main('#canvas', MyGame, 60, 160, 160, 2);
}
else {
	ig.main('#canvas', MyGame, 60, 240, 160, 3);
}

1 decade ago by Hazneliel

Ohhh the html off course, Thanks a lot for your help.
Page 1 of 1
« first « previous next › last »