{"id":14,"date":"2015-05-12T21:35:45","date_gmt":"2015-05-12T11:35:45","guid":{"rendered":"https:\/\/ocias.com\/blog\/?p=14"},"modified":"2015-05-13T11:14:09","modified_gmt":"2015-05-13T01:14:09","slug":"full-browser-window-unity-webgl","status":"publish","type":"post","link":"https:\/\/ocias.com\/blog\/full-browser-window-unity-webgl\/","title":{"rendered":"Full Browser Window Unity WebGL"},"content":{"rendered":"<p>Every amount of screen-space a player gives you is a gift &#8211; it&#8217;s a horrible waste to present your webGL content using the Unity default templates. It would be much nicer\u00a0to have our game fill up 100% of the window space we have available: a\u00a0full browser window\u00a0Unity webGL game.<\/p>\n<p><!--more--><\/p>\n<p>An example of what I&#8217;m talking about is <a href=\"https:\/\/ocias.com\/games\/acollectionofeyes\/\">here<\/a> (with an extra header and footer).<\/p>\n<p>It&#8217;s easiest to set this up starting from\u00a0the &#8216;minimal&#8217; player template, but you can add this onto any template, or better yet <a href=\"https:\/\/ocias.com\/blog\/how-to-set-up-a-unity-webgl-template\/\">make your own<\/a>.<\/p>\n<h2>The Set-up Process<\/h2>\n<p>All you need to do is\u00a0add these rules into the &#8220;style&#8221; tag in the head of the index.html file (or create a new CSS file and link it in if you prefer to keep things professional).<\/p>\n<pre>* {\r\n  margin: 0;\r\n  padding: 0;\r\n}\r\n\r\ncanvas {\r\n  width: 100%;\r\n  height: 100%;\r\n  position: absolute;\r\n}<\/pre>\n<p>The first part removes all padding and margins, to make sure nothing is adding extra white space. Browsers want even unstyled text to be readable so by default there is spacing around elements that we need to remove.<\/p>\n<p>The second part tells the canvas the game is rendering onto to stretch the full size of the browser window.<\/p>\n<p>The\u00a0&#8220;position: absolute;&#8221; rule\u00a0stops\u00a0your game from trying to maintain its aspect ratio, allowing the height to fully stretch.<\/p>\n<p>If you have any other divs or whatever objects wrapping your canvas, make sure to give them &#8220;height: 100%; width: 100%;&#8221; as well.<\/p>\n<p>That&#8217;s all there is to it!<\/p>\n<h2>Tips and Pitfalls<\/h2>\n<ul>\n<li>The internal resolution of your unity build will automatically update as the browser resized. This is good because you don&#8217;t need to worry about manually setting the resolution and maintaining the aspect ratio,\u00a0but on the other hand it does mean you have no control over render resolution and performance will decrease as the window size increases.<\/li>\n<li>Don&#8217;t forget to give your body a &#8220;background-color&#8221; as well, otherwise the screen will flash white before your canvas loads up.<\/li>\n<li>If you&#8217;re using a slightly different structure and have problems with scrollbars appearing and messing up your document, add &#8220;overflow: hidden;&#8221; to the body.<\/li>\n<li>Setting these CSS rules through the web inspector to test them doesn&#8217;t always work for me, but when they&#8217;re in the file it works fine.<\/li>\n<li>This styling makes it\u00a0nice and easy to embed\u00a0your build as an\u00a0iframe, letting you choose a resolution later.\u00a0This is great if you plan on uploading your game to\u00a0<a href=\"http:\/\/www.newgrounds.com\" target=\"_blank\">Newgrounds<\/a>,\u00a0<a href=\"http:\/\/www.kongregate.com\" target=\"_blank\">Kongregate<\/a>, etc.<\/li>\n<li>The resolution you set in &#8216;player settings&#8217; will now be completely ignored, so don&#8217;t stress about it.<\/li>\n<\/ul>\n<p>Hopefully you now have a working full browser window Unity WebGL build &#8211; shoot me a message if something&#8217;s not working! Next time I&#8217;ll write about\u00a0how to replace the default progress bar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every amount of screen-space a player gives you is a gift &#8211; it&#8217;s a horrible waste to present your webGL content using the Unity default templates. It would be much nicer\u00a0to have our game fill up 100% of the window space we have available: a\u00a0full browser window\u00a0Unity webGL game.<\/p>\n","protected":false},"author":1,"featured_media":110,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[9,3,10],"class_list":["post-14","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-tutorial","tag-unity3d","tag-webgl"],"_links":{"self":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":7,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions\/112"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/media\/110"}],"wp:attachment":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}