0

Possible Duplicate:
HTML5 Canvas resize to fit window

I'm developing HTML5 game for mobile phone.

I want to stretch the canvas to take the full phone width and hieght.

I'm using this code but it not very accurate:

ourCanvas = document.getElementById('gameCanvas');
context = ourGameCanvas.getContext( '2d' );
ourCanvas.width = $(window).width();
ourCanvas.height = $(window).height();

Any suggestions?

Community
  • 1
  • 1
Soliman
  • 1,132
  • 3
  • 12
  • 32

2 Answers2

0

Looks like your canvas doesn't refresh it's width and height on window resize or orientationchange event:

$(window).on("resize", fitCanvas);
fitCanvas();

function fitCanvas() {
    var ourCanvas = document.getElementById('gameCanvas');
    context = ourGameCanvas.getContext( '2d' );
    ourCanvas.width = $(window).width();
    ourCanvas.height = $(window).height();
}
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
0
.outerWidth()
.outerHeight()

?

And did you reset your layout? Like:

body, html, p, whatever { padding:0; margin:0; }
b1nary
  • 289
  • 3
  • 11