phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Canvas Size is Miscalculated

Open shawnsparks opened this issue 10 years ago • 3 comments

When trying to set the game to a width and height of "100" (100%) of parent, the game gets set to 100% of window instead.

index.html

<html>
<body style="maxWidth= 400px;">
<script src="phaser-2.5.0.js"></script>
<script src="game.js"></script>
</body>
</html>

game.js

let game = new Phaser.Game( '100', '100', Phaser.AUTO, '', { preload: preload, create: create, update: update } );

function preload() {
  console.log( document.getElementsByTagName( 'canvas' )[0].width ); // width of window, not canvas parent
}

This post appears to describe the same issue: http://www.html5gamedevs.com/topic/22216-trouble-filling-parent-element-in-dom/ Possibly related to #2458 and #2556

shawnsparks avatar Jun 25 '16 03:06 shawnsparks

There may be something unexpected going on here, but in the example above no parent has been given, so it defaults to the browser window as the docs say:

The width of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage width of the parent container, or the browser window if no parent is given.

photonstorm avatar Jun 25 '16 12:06 photonstorm

Thanks for calling that out. I was thinking width of body because the "Making Your First Game" talks about canvas getting added to the body if no id is specified.

All that said, the behavior is exactly the same if you use a parent element.

<html>
<body>
  <div id="parent"></div>
  ...scripts...
</body>
</html>
new Phaser.Game( '100', '100', Phaser.AUTO, 'parent', {...} );

shawnsparks avatar Jun 25 '16 18:06 shawnsparks

Thank you for taking the time to open this issue. However, official support for Phaser 2 has now ended as we focus on preparing Phaser 3 for beta release. In a bid to keep the project tidy, and avoid confusion, we are closing all v2 related issues.

This does not mean your issue won't be looked-at. In November 2016 the Phaser CE (Community Edition) project began. The aim of Phaser CE was to allow the community to continue v2 development. Since then it has gained significant traction, with many updates and releases.

If you are still interested in having your issue investigated we strongly recommend testing the latest Phaser CE release. And only if the problem persists, opening an issue on the Phaser CE repo.

photonstorm avatar Apr 20 '17 12:04 photonstorm