Jump to content

Fill parent with scaled game


Mars Arkane
 Share

Recommended Posts

Hello everybody.

I'd like my game to always fill the parent element, resizing it dynamically, while everything is, optionally, scaled by *2 (or other values). I currently accomplish this by setting the game size to the parent's size divided by 2, and then setting the user scale to 2.

window.addEventListener('resize', function()
{
	game.scale.setGameSize(parent.offsetWidth / 2, parent.offsetHeight / 2);
});

game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;
game.scale.setUserScale(2, 2);

This solution works fine (except for when the parent size is not dividable by 2), but I'm wondering if there's a better, built-in, solution. Scaling to the parent works great with RESIZE, but I couldn't find a way to also apply a scale to all elements. I know I could resize all individual elements, and I think I read something about scaling groups, but aside from my above solution feeling slightly better, I would prefer to let Phaser handle the scaling, especially since I'd prefer not to bother with calculating the actual world position for mouse input.

In short: Is there a way to apply a general, fixed scale to the entire game while filling the parent with it?

Thanks,

Mars

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...