Resizing HTML5 canvas while maintaining aspect ratio



  • I am working on a game that I plan to release for HTML5 and I am finding little documentation on how to change the size of the canvas. I want to make my game automatically scale to fit the size of the screen while still maintaining it's aspect ratio. How would I go around doing this?



  • Try this but it may mess up the position of everything

    FlxG.scaleMode = new FixedScaleAdjustSizeScaleMode();
    


  • Doesn't seem to change anything. How would I change the size of the HTML5 canvas? Like, instead of the canvas staying at a fixed size, it expands to fit the screen. This is useful for mobile, as resolutions are pretty much all over the place.



  • Try adding this in your Project.xml:

    <window if="html5" resizable="false" width="0" height="0" /> 
    

    According to this



  • Awesome! That totally worked.


Log in to reply