{"id":621,"date":"2017-03-05T11:01:37","date_gmt":"2017-03-05T10:01:37","guid":{"rendered":"http:\/\/davikingcode.com\/blog\/?p=621"},"modified":"2017-06-06T14:34:46","modified_gmt":"2017-06-06T12:34:46","slug":"haxe-pixijs-and-fullscreen-cross-platform-experiences","status":"publish","type":"post","link":"https:\/\/davikingcode.com\/blog\/haxe-pixijs-and-fullscreen-cross-platform-experiences\/","title":{"rendered":"Pixi.js, Haxe and browser&#8217;s fullpage cross-platform experiences"},"content":{"rendered":"<p>ADN 250 is a serious game around relationship marketing, like a Tupperware meeting. You must learn about different product by using them, then you can start selling theses products to different people and convince them to do the same extending your sellers network and making loads of money.<\/p>\n<p>The principal requirement for the project was to make an accessible game, without installation, accessible both on computer and device : a web game.<br \/>\n<a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/PC-Web-Screen.png\"><img loading=\"lazy\" class=\"wp-image-703 aligncenter\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/PC-Web-Screen-300x112.png\" alt=\"\" width=\"970\" height=\"362\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/PC-Web-Screen-300x112.png 300w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/PC-Web-Screen-768x287.png 768w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/PC-Web-Screen-1024x382.png 1024w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/PC-Web-Screen.png 1305w\" sizes=\"(max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/techno.png\"><img loading=\"lazy\" class=\" wp-image-696 alignleft\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/techno-135x300.png\" alt=\"\" width=\"204\" height=\"453\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/techno-135x300.png 135w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/techno.png 400w\" sizes=\"(max-width: 204px) 100vw, 204px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>What kind of technologies would you use if you were asked to build a full-page 2D game, available on the web by PCs and smartphones ?<\/p>\n<p>Here at Da Viking Code we chooses the famous <a href=\"http:\/\/www.pixijs.com\/\">Pixi.js<\/a> !<br \/>\nThis HTML5 javascript library using WebGL enable us to easily build 2D game on canvas.<\/p>\n<p>Unfortunately the JavaScript language isn&#8217;t the most comfortable one to use, mistake can be made because of the lack of type and compilation. If you feel comfortable with JavaScript that&#8217;s okay, but at Da Viking Code we prefer the strictly-typed and compiled <a href=\"https:\/\/haxe.org\/\">Haxe<\/a> language for our Web projects :). Using Pixi.s with Haxe isn&#8217;t hard, we use the well maintained <a class=\"user-mention\" href=\"https:\/\/github.com\/pixijs\/pixi-haxe\" rel=\"contributor\">Adireddy&#8217;s Haxe extern for Pixi.js<\/a> !<br \/>\n<!--more--><\/p>\n<p>Making a web game accessible on a huge variety of screens seize (from the small iPhone 4S to the big 27&#8243; screen some PC possess) require to be thought from the start.<\/p>\n<p>We choose to build the game as if it was to be displayed on a FullHD screen and at first frame call a <em>onResize()<\/em> function (onResize function is also call on screen resize). This function will call smaller resize function across the project, resulting in an easy to build and easy to resize well-organized solution.<\/p>\n<p><a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width11.png\"><img loading=\"lazy\" class=\"wp-image-679 aligncenter\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width11-300x112.png\" alt=\"\" width=\"828\" height=\"309\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width11-300x112.png 300w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width11-768x286.png 768w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width11-1024x382.png 1024w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width11.png 1303w\" sizes=\"(max-width: 828px) 100vw, 828px\" \/><\/a><em>The game running on a extra-wide PC screen, player just reach a new level.<\/em><\/p>\n<p>Sometime rescaling elements at runtime is not enough to get something good and light on devices, so we decided that the game will behave a little differently. The first thing is UI scaling, if we are on mobile all UI button are slightly bigger and some UI are just totally different.<\/p>\n<p>An other change, is the use of different level of quality for the game. Depending the starting resolution, we load a different texture pack resulting in faster loading and performances for smaller devices while preserving the best possible quality for high-end devices.<\/p>\n<p>To achieve different texture resolutions than will still appear at the same scale on the game, we need to tell Pixi at witch scale our textures are. In our project we have a full resolution texture pack (@1x) and an half resolution texture pack (@0.5x). Putting our texture in folders named as following will make Pixi.js understand the normal scale of a texture.<br \/>\n<a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/resolution3.jpg\"><img loading=\"lazy\" class=\"wp-image-692 aligncenter\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/resolution3-300x93.jpg\" alt=\"\" width=\"655\" height=\"203\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/resolution3-300x93.jpg 300w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/resolution3-768x239.jpg 768w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/resolution3.jpg 792w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><\/a><\/p>\n<p>For example a 1024 x 1024 texture in a @1x folder will have his scale on screen equal 1024 * 1 = 1024. A 512*512 in a @0.5x folder will have his scale on screen equal 512 * 2 = 1024. And finally, a 2048 x 2048 in a @2x folder will have his scale on screen equal to 2048 * 0.5 = 1024.<br \/>\nAt the end, we have 3 different qualities of texture, but the same scale on screen regardless their original width and length.<\/p>\n<p><a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width12.png\"><img loading=\"lazy\" class=\"wp-image-671 aligncenter\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width12-300x112.png\" alt=\"\" width=\"635\" height=\"237\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width12-300x112.png 300w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width12-768x286.png 768w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width12-1024x382.png 1024w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/Width12.png 1304w\" sizes=\"(max-width: 635px) 100vw, 635px\" \/><\/a><em>In this panel, the player can recruit people to sell his products.<\/em><\/p>\n<p>The last difficulty we faced was achieving Fullpage on iOS. Our canvas was inside an element with an <strong>absolute<\/strong> position which cause iOS devices to overlap a part of the game with their browser navigation bar on landscape orientation.<br \/>\nAfter many searches on the web and multiple test, the solution was finally to use <strong>fixed<\/strong> positioning for the container of our game combined with a <strong>scrollTo(0, 0)<\/strong>.<\/p>\n<p><a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/IphonePresetTransparentFont.png\"><img loading=\"lazy\" class=\"wp-image-650 aligncenter\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/IphonePresetTransparentFont-300x112.png\" alt=\"\" width=\"1014\" height=\"378\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/IphonePresetTransparentFont-300x112.png 300w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/IphonePresetTransparentFont-768x287.png 768w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/IphonePresetTransparentFont-1024x382.png 1024w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/IphonePresetTransparentFont.png 1305w\" sizes=\"(max-width: 1014px) 100vw, 1014px\" \/><\/a><\/p>\n<p>To conclude, choicing Pixi.js with Haxe was coherent with the ambition of the project:<br \/>\n&#8211; Pixi has all you want to make your responsive web game on PC and mobile devices, resizing with the browser and managing different resolutions for texture packs.<br \/>\n&#8211; Haxe is a good friend of Pixi.js thanks to awesome externs, offering both a typed, secure environment for your application and the possibility to break out its logic to do some more js-like coding thanks to dynamic type and untyped line.<br \/>\nThanks to these technologies the project goes well and we were able to pass all difficulties we came across, comforting us in our technological choice.<\/p>\n<p>On a side note, we&#8217;d some trouble loading a XML file with Pixi.js loader. Here is a reminder:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar xmlTextString:String = new js.html.XMLSerializer().serializeToString(loader.resources.text.data.childNodes[0]);\r\nvar XML = Xml.parse(xmlTextString);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ADN 250 is a serious game around relationship marketing, like a Tupperware meeting. You must learn about different product by using them, then you can start selling theses products to different people and convince them to do the same extending your sellers network and making loads of money. The principal requirement for the project was &hellip; <a href=\"https:\/\/davikingcode.com\/blog\/haxe-pixijs-and-fullscreen-cross-platform-experiences\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Pixi.js, Haxe and browser&#8217;s fullpage cross-platform experiences<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_discordance_state":"","_discordance_checked":true},"categories":[4],"tags":[27,42,31,30,28],"_links":{"self":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/621"}],"collection":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/comments?post=621"}],"version-history":[{"count":84,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/621\/revisions"}],"predecessor-version":[{"id":752,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/621\/revisions\/752"}],"wp:attachment":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/media?parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/categories?post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/tags?post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}