Jump to content

Getting true width/height of game


Recommended Posts

Hey guys,

this sound a bit dumb, but I'm struggling to find the actual height of my game.  I'm working on a responsive game setup, so I'm setting an initial height, then using SHOW_ALL as my scale mode, and then in Chrome developer tools I've got it showing my page in responsive mode.  I have my game in a div with css setting the div to 100%.  As I use the grab handles in Chrome's developer tools to adjust the game's width and height to simulate different aspect ratios/orientations, I am logging the game height to the console so that I can do some calculations and adjust the top margin via css, so that my game is vertically centred within the html page.  Problem is, no matter what I've tried (game.height, game.scale.height, game.canvas.height) it always reports the same, constant, original height I set using game.scale.setGameSize(), even when I am physically changing the height in the browser window.

Any ideas how I can get the real pixel height of the phaser game area?

Cheers.

Link to post
Share on other sites

Thanks, but yeah, I tried both of those, and they are just reporting the original size I set, even after the browser window is scaled, rather than the real pixel value of the visible game area.

I've also tried logging the 'parentBounds' argument from the resize callback ( game.scale.setResizeCallback ) and for some reason that returns a rectangle which is always 0,0,0,0.

I have a feeling I'm overlooking something obvious.  Is there a way to find how much scaleManager.SHOW_ALL has actually scaled the original size of the game?  If I could get at that, then I could simply multiply that scale factor to the original dimensions to calulate the new pixel size of the game.

Link to post
Share on other sites

Thanks samme - although game.scale.height just reports a static value for me, the original game height set using game.scale.setGameSize(), irrespective of any changes made to the browser window size.  It appears to be the value stored before the any scaling is applied by the SHOW_ALL scale mode.  Whereas using the pure javascript method - document.getElementById("parentDiv").clientHeight; - that appears to report accurately the actual height.

 

Link to post
Share on other sites
  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...