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

1 decade ago by adshead


I'm designing a game where the levels are different sizes in terms of their height. Some are quite square where as others are long and thin (like a corridor).

I currently have a canvas that is tall enough to display any of the levels, but for the levels that aren't very tall I'd like to shrink the canvas height so that I don't see any unused areas of the canvas.

Is it possible to auto-resize the canvas height for each level?

If it's not possible, is it at least possible to center the narrow levels so they appear in the center of the canvas by perhaps setting some kind of offset?

Any help/suggestions appreciated!


1 decade ago by dominic

The size of the canvas element can be changed through ig.system.resize. So you could overwrite the loadLevel() method in your Game class with something like this:
loadLevel: function( data ) {
	this.parent( data );
	// Calculate the height in pixels of the level we just loaded
	var newHeight = this.collisionMap.height * this.collisionMap.tilesize;
	// Resize the canvas height, keep the current width
	ig.system.resize( ig.system.width, newHeight );

You can also change the screen position ("offset") through the Game's screen.x and screen.y properties.

1 decade ago by adshead

Fantastic - Thanks for the help dominic I will give that a try.

1 decade ago by Jaha

@dominic I cant seem to get this to work, it indeed resizes the canvas but doesnt scale the entities/backgrounds. Im trying to essentially go from a intro scene of 1280x704@1 to the main game of 640x352@2. If I remove the scale it looks correct, just 1/2 the size i need it.

// main.js
  ig.main('#canvas', IntroScene, 60, 1280, 704, 1);

// scenes/intro.js
      if ( > 5) {

// main.js
(i'm using the leveldata plugin to pass the data from WM)
    loadLevel: function(level) {

      // Resize the canvas and scale if level needs it
      // 640x352@2
      ig.system.resize( || ig.system.width, || ig.system.height, || ig.system.scale);
Page 1 of 1
« first « previous next › last »