{"id":814,"date":"2017-11-28T20:05:38","date_gmt":"2017-11-28T19:05:38","guid":{"rendered":"http:\/\/www.pixnbgames.com\/blog\/?p=814"},"modified":"2017-11-28T20:05:38","modified_gmt":"2017-11-28T19:05:38","slug":"how-to-use-libgdx-tiled-scene-design","status":"publish","type":"post","link":"https:\/\/www.pixnbgames.com\/blog\/libgdx\/how-to-use-libgdx-tiled-scene-design\/","title":{"rendered":"How to use libGDX + Tiled: scene design"},"content":{"rendered":"<p>The file which defines the design of the scene is the map file. There are many ways to generate this file from our tileset.<\/p>\n<h3>Options<\/h3>\n<p>We can create the map file manually, or we can use any of the existing generic map editors, or even use the map editor included in the game engine (if our game engine provides it).<\/p>\n<h4>Own generation<\/h4>\n<p>If we create the map manually or with a custom editor we are completely free to define the map format according with our necessities. We need at least two basic functions: identifing each tile of the tileset, and set how the tiles composes the scene. For example, a simple approach could be having a single tile, and a text file with ones and zeros indicating which parts of the scene are \u00abfilled\u00bb and which ones are not:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-766\" src=\"http:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/simle_tiled_map-1024x296.png\" alt=\"\" width=\"530\" height=\"153\" srcset=\"https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/simle_tiled_map-1024x296.png 1024w, https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/simle_tiled_map-300x87.png 300w, https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/simle_tiled_map-768x222.png 768w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/p>\n<p>Making our custom map implementation implies we also need to write the neccesary code to read and draw the map in our game. This can be a problem for some developers because the time and knowledges we need to do it.<\/p>\n<h4>Generic editor<\/h4>\n<p>If we use a generic map editor we get the advantage that them are programs speciffically designed for map creation and them have the neccessary tools to do it. It&#8217;s important to know if our game engine supports the maps generated with the used editor. If not, we need to write the code to read and render the maps.<\/p>\n<h4>Editor included in game engine<\/h4>\n<p>Some game engines, like <em>Unity<\/em>, <em>GameMaker<\/em> or <em>SpriteKit<\/em> have its own tiled map editor. This allows to manage all the design process from the same tool, furthermore we have total guaranty of the compatibility between the map and the game engine. Maybe a disadvantage of this approach is that we are required to use a concrete game engine.<\/p>\n<p>&nbsp;<\/p>\n<h3>Tiled Map Editor<\/h3>\n<p>In my case, I use <a href=\"http:\/\/www.mapeditor.org\/\" target=\"_blank\" rel=\"noopener\"><em>Tiled Map Editor<\/em><\/a> because it covers my necessities for levels creation and it also is supportted by <em>libGDX<\/em>, so it&#8217;s easy to use both together.<\/p>\n<p>To design the scene from our tileset created on <a href=\"http:\/\/www.pixnbgames.com\/blog\/libgdx\/how-to-use-libgdx-tiled-creating-the-tileset\/\">the previous article<\/a>, create a new project in <em>Tiled<\/em> with <em>Orthogonal<\/em> orientation, and setting our tiles dimension: 16 pixels for width and height. The map will have 30 tiles for width and 20 tiles for height.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-739\" src=\"http:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.16.03-300x204.png\" alt=\"\" width=\"300\" height=\"204\" srcset=\"https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.16.03-300x204.png 300w, https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.16.03-768x522.png 768w, https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.16.03.png 1012w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Save the file with the name <em><strong>level.tmx<\/strong><\/em> on the same location where <em>tileset.png<\/em> is (really is not neccessary to use the same location but it makes the work easier).<\/p>\n<p>Next we must load the tileset to the project. We do it from the \u00ab<em>Tilesets<\/em>\u00bb panel, located on the bottom right side of the application. Click the icon <img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.31.07.png\" alt=\"\" width=\"18\" height=\"21\" \/> &gt; Select our file <em>tileset.png<\/em>, set 16 pixels for width and height of tiles and click <em>OK<\/em>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-742\" src=\"http:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/importar-conjunto-de-patrones.gif\" alt=\"\" width=\"1804\" height=\"1120\" \/><\/p>\n<p>Now the tileset is showed on the <em>Tilesets<\/em> area. Using the tool <em>Stamp Brush<\/em> we draw the scene using the tiles. My composition is the next one:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-743\" src=\"http:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.20.20.png\" alt=\"\" width=\"976\" height=\"656\" srcset=\"https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.20.20.png 976w, https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.20.20-300x202.png 300w, https:\/\/www.pixnbgames.com\/blog\/wp-content\/uploads\/2017\/11\/Captura-de-pantalla-2017-11-22-a-las-20.20.20-768x516.png 768w\" sizes=\"(max-width: 976px) 100vw, 976px\" \/><\/p>\n<p>In the next article we will start to draw our scene with <em>libGDX<\/em>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The file which defines the design of the scene is the map file. There are many ways to generate this file from our tileset. Options We can create the map file manually, or we can use any of the existing <a class=\"more-link\" href=\"https:\/\/www.pixnbgames.com\/blog\/libgdx\/how-to-use-libgdx-tiled-scene-design\/\">Seguir leyendo <span class=\"screen-reader-text\">  How to use libGDX + Tiled: scene design<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":738,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[15,55],"language":[4],"_links":{"self":[{"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/posts\/814"}],"collection":[{"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/comments?post=814"}],"version-history":[{"count":2,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":816,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions\/816"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/media\/738"}],"wp:attachment":[{"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/media?parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/categories?post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/tags?post=814"},{"taxonomy":"language","embeddable":true,"href":"https:\/\/www.pixnbgames.com\/blog\/wp-json\/wp\/v2\/language?post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}