<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX</id>
	<title>Tuto tiny-ecs 2d platformer Part 4 LevelX - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX"/>
	<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;action=history"/>
	<updated>2026-11-17T12:48:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24718&amp;oldid=prev</id>
		<title>MoKaLux at 00:43, 26 October 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24718&amp;oldid=prev"/>
		<updated>2025-10-26T00:43:47Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;amp;diff=24718&amp;amp;oldid=24666&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24666&amp;oldid=prev</id>
		<title>MoKaLux at 01:21, 7 September 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24666&amp;oldid=prev"/>
		<updated>2025-09-07T01:21:43Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:21, 7 September 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l6&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The LevelX scene holds the game loop and controls the flow of each levels.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The LevelX scene holds the game loop and controls the flow of each levels.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When the scene loads, it constructs the level &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;which is organised &lt;/del&gt;into layers, more on that in the code comments below ;-)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When the scene loads, it constructs the level into layers, more on that in the code comments below ;-)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The code is not that long given it takes care of all levels of the game: level 1, 2 and 3. To make it easy to follow and debug, I use &amp;#039;&amp;#039;&amp;#039;FIGlet&amp;#039;&amp;#039;&amp;#039; (https://en.wikipedia.org/wiki/FIGlet).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The code is not that long given it takes care of all levels of the game: level 1, 2 and 3. To make it easy to follow and debug, I use &amp;#039;&amp;#039;&amp;#039;FIGlet&amp;#039;&amp;#039;&amp;#039; (https://en.wikipedia.org/wiki/FIGlet).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l241&quot;&gt;Line 241:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 241:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== LevelX:init&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;() &lt;/del&gt;===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== LevelX Code comments ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== LevelX:init ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== plugins ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== plugins ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Here we initialize our plugins. tiny-ecs is declared as a Class variable (&amp;#039;&amp;#039;self.tiny&amp;#039;&amp;#039;) because we use it outside the &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function. Bump can be local as we only use it in the &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Here we initialize our plugins. tiny-ecs is declared as a Class variable (&amp;#039;&amp;#039;self.tiny&amp;#039;&amp;#039;) because we use it outside the &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function. Bump can be local as we only use it in the &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is worth noting that &#039;&#039;tiny.tworld&#039;&#039; is attached to &#039;&#039;self.tiny&#039;&#039; variable. This makes it &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;much &lt;/del&gt;easier to access through the rest of the code in our project.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is worth noting that &#039;&#039;tiny.tworld&#039;&#039; is attached to &#039;&#039;self.tiny&#039;&#039; variable. This makes it easier to access through the rest of the code in our project.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== layers ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== layers ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l257&quot;&gt;Line 257:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 258:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use &amp;#039;&amp;#039;&amp;#039;Tiled&amp;#039;&amp;#039;&amp;#039; to build our levels (https://www.mapeditor.org/) and we call the &amp;#039;&amp;#039;TiledLevels Class&amp;#039;&amp;#039; to manage the parsing of the Tiled elements in our game.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use &amp;#039;&amp;#039;&amp;#039;Tiled&amp;#039;&amp;#039;&amp;#039; to build our levels (https://www.mapeditor.org/) and we call the &amp;#039;&amp;#039;TiledLevels Class&amp;#039;&amp;#039; to manage the parsing of the Tiled elements in our game.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;We dedicate an entire folder for Tiled in our project and we &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;will explain &lt;/del&gt;more about it down below&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;We dedicate an entire folder for Tiled in our project and we &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;talk &lt;/ins&gt;more about it down below&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The &amp;#039;&amp;#039;mapdef&amp;#039;&amp;#039; is a table which has the map definition (dimensions), so we can pass it to functions that will require the size of the map for calculations.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The &amp;#039;&amp;#039;mapdef&amp;#039;&amp;#039; is a table which has the map definition (dimensions), so we can pass it to functions that will require the size of the map for calculations.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l272&quot;&gt;Line 272:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 273:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use a camera in our game and &amp;#039;&amp;#039;camfollowoffsety&amp;#039;&amp;#039; will offset the camera following the player. It is easier to change it being a variable.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use a camera in our game and &amp;#039;&amp;#039;camfollowoffsety&amp;#039;&amp;#039; will offset the camera following the player. It is easier to change it being a variable.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use a slightly modified version of &#039;&#039;&#039;MultiPain&#039;&#039;&#039;&#039;s (aka rrraptor on Gideros forum) &#039;&#039;&#039;GCam&#039;&#039;&#039; Class for our camera.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use a slightly modified version of &#039;&#039;&#039;MultiPain&#039;&#039;&#039;&#039;s (aka rrraptor on Gideros forum) &#039;&#039;&#039;GCam&#039;&#039;&#039; Class for our camera. We pass &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;it &lt;/ins&gt;the &#039;&#039;mainlayer&#039;&#039; as the content and the player1 to follow.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Please grab it here &#039;&#039;&#039;[[Media:gcam_beu.lua]]&#039;&#039;&#039; &#039;&#039;&#039;(tip: right click and save link as)&#039;&#039;&#039; and put it in the &quot;&#039;&#039;&#039;classes&#039;&#039;&#039;&quot; folder.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We pass the &#039;&#039;mainlayer&#039;&#039; as the content and the player1 to follow.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Using the map definition we set the camera bounds. We also set the soft and the dead size parameters and we tell it to follow the player.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Using the map definition we set the camera bounds. We also set the soft and the dead size parameters and we tell it to follow the player.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l305&quot;&gt;Line 305:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 302:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== TiledLevels Class ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== TiledLevels Class ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;To better organise the game, I put all files related to &#039;&#039;&#039;Tiled&#039;&#039;&#039; in a &#039;&#039;&#039;tiled&#039;&#039;&#039; folder.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s have a look at how we construct our levels.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s have a look at how we construct our levels.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;As mentionned before I use &#039;&#039;&#039;Tiled&#039;&#039;&#039;. &lt;/del&gt;In Tiled we add many layers, in our case &#039;&#039;&#039;Object Layers&#039;&#039;&#039;. Each layers have a &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;specific &lt;/del&gt;name &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to better build our levels &lt;/del&gt;(eg. &#039;&#039;physics_ptpfs&#039;&#039;, &#039;&#039;physics_coins&#039;&#039;, &#039;&#039;bg_deco_images&#039;&#039;, ...). In each layers we draw the level using shapes (rectangles, ellipses, ...). Shapes are also used to position the actors in the level, like the player, the enemies, moving platforms, ...&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In Tiled we add many layers, in our case &#039;&#039;&#039;Object Layers&#039;&#039;&#039;. Each layers have a &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;type and a &lt;/ins&gt;name (eg. &#039;&#039;physics_ptpfs&#039;&#039;, &#039;&#039;physics_coins&#039;&#039;, &#039;&#039;bg_deco_images&#039;&#039;, ...). In each layers we draw the level using shapes (rectangles, ellipses, ...). Shapes are also used to position the actors in the level, like the player, the enemies, moving platforms, ..&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Once the level is done in Tiled, we export it as a &#039;&#039;&#039;lua&#039;&#039;&#039; file Gideros will use (read the layers name, the shapes, the color, the position, ...).&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=== TiledLevels Class Code comments ===&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The very first thing we do is include the Tiled lua file. I also set up some variables to check if we are testing a prototype level and if we are in development mode.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==== Tileset ====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;This is the classic: a tileset with a tilemap image (&#039;&#039;&#039;Tile Layer&#039;&#039;&#039; in Tiled). We don&#039;t use tilsets in this game but feel free to do so. The code extracts the tilemap info: number of columns, rows, tile id (gid) and texture&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;In the TiledLevels Class &lt;/del&gt;we read the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.lua file exported from Tiled &lt;/del&gt;and &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;we use it to build &lt;/del&gt;the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;shapes &lt;/del&gt;in &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the game using Gideros &lt;/del&gt;&#039;&#039;&#039;[[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Shape&lt;/del&gt;]]&#039;&#039;&#039;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. In order to build &lt;/del&gt;the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;shapes, I have written several classes for each one of them: &#039;&#039;Tiled_Shape_Ellipse&#039;&#039;, &#039;&#039;Tiled_Shape_Point&#039;&#039;, &#039;&#039;Tiled_Shape_Polygon&#039;&#039;, ..&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==== Tileset images ====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Instead of tilesets we use single images to make our levels. Here &lt;/ins&gt;we read the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;gid &lt;/ins&gt;and the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;image path and store them &lt;/ins&gt;in &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tables. The tables are then turned into &lt;/ins&gt;&#039;&#039;&#039;[[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;TexturePack&lt;/ins&gt;]]&#039;&#039;&#039; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;so &lt;/ins&gt;the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;game runs faster&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;When &lt;/del&gt;we &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;read the Tiled file we look for &lt;/del&gt;the layers name &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;and we call &lt;/del&gt;the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;appropriate shape class and voilà, &lt;/del&gt;we &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;see &lt;/del&gt;the level &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:-)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==== Build Level ====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;To build a level, &lt;/ins&gt;we &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;iterate all &lt;/ins&gt;the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tilemap &lt;/ins&gt;layers &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;according to their &#039;&#039;&#039;type&#039;&#039;&#039; and their &#039;&#039;&#039;&lt;/ins&gt;name&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;. We either build shapes &lt;/ins&gt;the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;physics world&#039;&#039;&#039; can use or &lt;/ins&gt;we &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;add images to decorate &lt;/ins&gt;the level &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;using the &#039;&#039;parseImage&#039;&#039; function.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;note&#039;&#039;&#039;: we &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;give each shape a color and a texture when reading the &lt;/del&gt;Tiled &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;file &lt;/del&gt;in &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the TiledLevels Class&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;note&#039;&#039;&#039;: we &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;don&#039;t use &lt;/ins&gt;Tiled &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;Tile Layer&#039;&#039; &lt;/ins&gt;in &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;this game but you can, Build Level takes care of it for you in &#039;&#039;layer.type == &quot;tilelayer&quot;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;better organise &lt;/del&gt;the game, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;I put all files related to Tiled in a &lt;/del&gt;&#039;&#039;&#039;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tiled&lt;/del&gt;&#039;&#039;&#039; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;folder&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;build the shapes in &lt;/ins&gt;the game &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;we use the Gideros &#039;&#039;&#039;[[Shape]]&#039;&#039;&#039; class. I have written several classes for each one of them: &#039;&#039;Tiled_Shape_Ellipse&#039;&#039;, &#039;&#039;Tiled_Shape_Point&#039;&#039;&lt;/ins&gt;, &#039;&#039;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tiled_Shape_Polygon&lt;/ins&gt;&#039;&#039;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, ... . When we read the Tiled file we look for the layer name, if the layer contains shapes, we call the appropriate shape class and voilà :-). The &#039;&#039;buildShapes&lt;/ins&gt;&#039;&#039; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function is at the very bottom of the class&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;You can read more about Tiled and Gideros here: [[Tiled_Bump]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;That&#039;s basically how we build our levels using Tiled. &lt;/ins&gt;You can read more about Tiled and Gideros here: [[Tiled_Bump]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Next? ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Next? ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24664&amp;oldid=prev</id>
		<title>MoKaLux: /* TiledLevels Class */</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24664&amp;oldid=prev"/>
		<updated>2025-09-06T05:39:03Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;TiledLevels Class&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:39, 6 September 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l311&quot;&gt;Line 311:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 311:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In the TiledLevels Class we read the .lua file exported from Tiled and we use it to build the shapes in the game using Gideros &amp;#039;&amp;#039;&amp;#039;[[Shape]]&amp;#039;&amp;#039;&amp;#039;. In order to build the shapes, I have written several classes for each one of them: &amp;#039;&amp;#039;Tiled_Shape_Ellipse&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Tiled_Shape_Point&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Tiled_Shape_Polygon&amp;#039;&amp;#039;, ...&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In the TiledLevels Class we read the .lua file exported from Tiled and we use it to build the shapes in the game using Gideros &amp;#039;&amp;#039;&amp;#039;[[Shape]]&amp;#039;&amp;#039;&amp;#039;. In order to build the shapes, I have written several classes for each one of them: &amp;#039;&amp;#039;Tiled_Shape_Ellipse&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Tiled_Shape_Point&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Tiled_Shape_Polygon&amp;#039;&amp;#039;, ...&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When we read the Tiled file we call the appropriate shape class and voilà, we see the level :-)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When we read the Tiled file &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;we look for the layers name and &lt;/ins&gt;we call the appropriate shape class and voilà, we see the level :-)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;#039;&amp;#039;&amp;#039;note&amp;#039;&amp;#039;&amp;#039;: we give each shape a color and a texture when reading the Tiled file in the TiledLevels Class&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;#039;&amp;#039;&amp;#039;note&amp;#039;&amp;#039;&amp;#039;: we give each shape a color and a texture when reading the Tiled file in the TiledLevels Class&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24663&amp;oldid=prev</id>
		<title>MoKaLux at 05:35, 6 September 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24663&amp;oldid=prev"/>
		<updated>2025-09-06T05:35:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:35, 6 September 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l254&quot;&gt;Line 254:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 254:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is a &amp;#039;&amp;#039;player1inputlayer&amp;#039;&amp;#039; which will capture the user input to control the player, it won&amp;#039;t hold any graphics.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is a &amp;#039;&amp;#039;player1inputlayer&amp;#039;&amp;#039; which will capture the user input to control the player, it won&amp;#039;t hold any graphics.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== levels ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tiled &lt;/ins&gt;levels ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use &amp;#039;&amp;#039;&amp;#039;Tiled&amp;#039;&amp;#039;&amp;#039; to build our levels (https://www.mapeditor.org/) and we call the &amp;#039;&amp;#039;TiledLevels Class&amp;#039;&amp;#039; to manage the parsing of the Tiled elements in our game.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We use &amp;#039;&amp;#039;&amp;#039;Tiled&amp;#039;&amp;#039;&amp;#039; to build our levels (https://www.mapeditor.org/) and we call the &amp;#039;&amp;#039;TiledLevels Class&amp;#039;&amp;#039; to manage the parsing of the Tiled elements in our game.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;We dedicate an entire folder for Tiled in our project and we will explain more about it &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;in the next chapter of the tutorial&lt;/del&gt;&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;We dedicate an entire folder for Tiled in our project and we will explain more about it &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;down below&lt;/ins&gt;&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The &amp;#039;&amp;#039;mapdef&amp;#039;&amp;#039; is a table which has the map definition (dimensions), so we can pass it to functions that will require the size of the map for calculations.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The &amp;#039;&amp;#039;mapdef&amp;#039;&amp;#039; is a table which has the map definition (dimensions), so we can pass it to functions that will require the size of the map for calculations.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l292&quot;&gt;Line 292:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 292:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== LevelX:onEnterFrame &amp;#039;&amp;#039;&amp;#039;THE GAME LOOP&amp;#039;&amp;#039;&amp;#039; ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== LevelX:onEnterFrame &amp;#039;&amp;#039;&amp;#039;THE GAME LOOP&amp;#039;&amp;#039;&amp;#039; ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Before the game loop, I declare a local variable&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/del&gt;&#039;&#039;timer&#039;&#039; is the time before transitioning to the next level.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Before the game loop, I declare a local variable &#039;&#039;timer&#039;&#039; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;which &lt;/ins&gt;is the time before transitioning to the next level.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If we beat the level then we go to the next level or the &amp;#039;&amp;#039;&amp;#039;Win&amp;#039;&amp;#039;&amp;#039; scene.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If we beat the level then we go to the next level or the &amp;#039;&amp;#039;&amp;#039;Win&amp;#039;&amp;#039;&amp;#039; scene.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Otherwise if the game is not paused we update the camera and the tiny-ecs world. &#039;&#039;&#039;tiny-ecs world&#039;&#039;&#039; runs all the systems (animations, movements, AI, ...). Some systems will be called only once, others every frame per second.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Otherwise&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;if the game is not paused we update the camera and the tiny-ecs world. &#039;&#039;&#039;tiny-ecs world&#039;&#039;&#039; runs all the systems (animations, movements, AI, ...). Some systems will be called only once, others every frame per second&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. More on Systems later on in this tutorial&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== LevelX:myKeysPressed ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== LevelX:myKeysPressed ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l307&quot;&gt;Line 307:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 307:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s have a look at how we construct our levels.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s have a look at how we construct our levels.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The code&lt;/del&gt;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;As mentionned before I use &#039;&#039;&#039;Tiled&#039;&#039;&#039;. In Tiled we add many layers, in our case &#039;&#039;&#039;Object Layers&#039;&#039;&#039;. Each layers have a specific name to better build our levels (eg. &#039;&#039;physics_ptpfs&#039;&#039;, &#039;&#039;physics_coins&#039;&#039;, &#039;&#039;bg_deco_images&#039;&#039;, ...). In each layers we draw the level using shapes (rectangles, ellipses, ...). Shapes are also used to position the actors in the level, like the player, the enemies, moving platforms, ...&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;syntaxhighlight lang=&quot;lua&quot;&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;In the TiledLevels Class we read the .lua file exported from Tiled and we use it to build the shapes in the game using Gideros &#039;&#039;&#039;[[Shape]]&#039;&#039;&#039;. In order to build the shapes, I have written several classes for each one of them&lt;/ins&gt;: &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;Tiled_Shape_Ellipse&#039;&#039;, &#039;&#039;Tiled_Shape_Point&#039;&#039;, &#039;&#039;Tiled_Shape_Polygon&#039;&#039;, ...&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;When we read the Tiled file we call the appropriate shape class and voilà, we see the level :-)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &#039;&#039;&#039;note&#039;&#039;&#039;: we give each shape a color and a texture when reading the Tiled file in the TiledLevels Class&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;To better organise the game, I put all files related to Tiled in a &#039;&#039;&#039;tiled&#039;&#039;&#039; folder.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;You can read more about Tiled and Gideros here: [[Tiled_Bump]].&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Next? ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Next? ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24662&amp;oldid=prev</id>
		<title>MoKaLux: wip</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_2d_platformer_Part_4_LevelX&amp;diff=24662&amp;oldid=prev"/>
		<updated>2025-09-06T02:26:49Z</updated>

		<summary type="html">&lt;p&gt;wip&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
== the levelX.lua file ==&lt;br /&gt;
This is where all the fun begins!&lt;br /&gt;
&lt;br /&gt;
The LevelX scene holds the game loop and controls the flow of each levels.&lt;br /&gt;
&lt;br /&gt;
When the scene loads, it constructs the level which is organised into layers, more on that in the code comments below ;-)&lt;br /&gt;
&lt;br /&gt;
The code is not that long given it takes care of all levels of the game: level 1, 2 and 3. To make it easy to follow and debug, I use &amp;#039;&amp;#039;&amp;#039;FIGlet&amp;#039;&amp;#039;&amp;#039; (https://en.wikipedia.org/wiki/FIGlet).&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;I use this one https://sourceforge.net/projects/figletgenerator/&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
LevelX = Core.class(Sprite)&lt;br /&gt;
&lt;br /&gt;
local ispaused = false&lt;br /&gt;
&lt;br /&gt;
function LevelX:init()&lt;br /&gt;
	-- move the cursor out of the way&lt;br /&gt;
	if not application:isPlayerMode() then&lt;br /&gt;
		local sw, sh = application:get(&amp;quot;screenSize&amp;quot;) -- the user&amp;#039;s screen size!&lt;br /&gt;
		application:set(&amp;quot;cursorPosition&amp;quot;, sw-10, sh-10) -- 0, 0&lt;br /&gt;
	end&lt;br /&gt;
	-- _____  _     _    _  _____ _____ _   _  _____ &lt;br /&gt;
	--|  __ \| |   | |  | |/ ____|_   _| \ | |/ ____|&lt;br /&gt;
	--| |__) | |   | |  | | |  __  | | |  \| | (___  &lt;br /&gt;
	--|  ___/| |   | |  | | | |_ | | | | . ` |\___ \ &lt;br /&gt;
	--| |    | |___| |__| | |__| |_| |_| |\  |____) |&lt;br /&gt;
	--|_|    |______\____/ \_____|_____|_| \_|_____/ &lt;br /&gt;
	-- tiny-ecs&lt;br /&gt;
	if not self.tiny then self.tiny = require &amp;quot;classes/tiny-ecs&amp;quot; end&lt;br /&gt;
	self.tiny.tworld = self.tiny.world()&lt;br /&gt;
	-- cbump (bworld)&lt;br /&gt;
	local bump = require &amp;quot;cbump&amp;quot;&lt;br /&gt;
	local bworld = bump.newWorld() -- 16, grid cell size, default = 64&lt;br /&gt;
	-- _           __     ________ _____   _____ &lt;br /&gt;
	--| |        /\\ \   / /  ____|  __ \ / ____|&lt;br /&gt;
	--| |       /  \\ \_/ /| |__  | |__) | (___  &lt;br /&gt;
	--| |      / /\ \\   / |  __| |  _  / \___ \ &lt;br /&gt;
	--| |____ / ____ \| |  | |____| | \ \ ____) |&lt;br /&gt;
	--|______/_/    \_\_|  |______|_|  \_\_____/ &lt;br /&gt;
	local layers = {}&lt;br /&gt;
	layers[&amp;quot;main&amp;quot;] = Sprite.new() -- one Sprite to hold them all&lt;br /&gt;
	layers[&amp;quot;bg&amp;quot;] = Sprite.new() -- bg layer&lt;br /&gt;
	layers[&amp;quot;bgfx&amp;quot;] = Sprite.new() -- bg fx layer&lt;br /&gt;
	layers[&amp;quot;actors&amp;quot;] = Sprite.new() -- actors layer&lt;br /&gt;
	layers[&amp;quot;fgfx&amp;quot;] = Sprite.new() -- fg fx layer&lt;br /&gt;
	layers[&amp;quot;fg&amp;quot;] = Sprite.new() -- fg layer&lt;br /&gt;
	layers[&amp;quot;player1input&amp;quot;] = Sprite.new() -- player1 input layer&lt;br /&gt;
	-- _      ________      ________ _       _____ &lt;br /&gt;
	--| |    |  ____\ \    / /  ____| |     / ____|&lt;br /&gt;
	--| |    | |__   \ \  / /| |__  | |    | (___  &lt;br /&gt;
	--| |    |  __|   \ \/ / |  __| | |     \___ \ &lt;br /&gt;
	--| |____| |____   \  /  | |____| |____ ____) |&lt;br /&gt;
	--|______|______|   \/   |______|______|_____/ &lt;br /&gt;
	self.tiledlevels = {}&lt;br /&gt;
	self.tiledlevels[1] = &amp;quot;tiled/lvl001/_level1_proto&amp;quot; -- lua file without extension&lt;br /&gt;
	self.tiledlevels[2] = &amp;quot;tiled/lvl001/level1&amp;quot; -- lua file without extension&lt;br /&gt;
--	self.tiledlevels[3] = &amp;quot;tiled/lvl002/level1_proto&amp;quot; -- lua file without extension&lt;br /&gt;
	local mapdef = {} -- game area (rect: top, left, right, bottom)&lt;br /&gt;
	local zoom = 1 -- 1.3, 1.5, 1.7&lt;br /&gt;
	local camfollowoffsety = 28 -- 32, 36, 48, camera follow player1 y offset, magik XXX&lt;br /&gt;
	self.tiny.player1inventory = {} -- player1 inventory&lt;br /&gt;
	self.tiny.numberofcoins = 0&lt;br /&gt;
	local currlevel = TiledLevels.new(&lt;br /&gt;
		self.tiledlevels[g_currlevel], self.tiny, bworld, layers&lt;br /&gt;
	)&lt;br /&gt;
	-- currlevel map definition (top, left, right, bottom) for the camera&lt;br /&gt;
	mapdef.t, mapdef.l =&lt;br /&gt;
		currlevel.mapdef.t, currlevel.mapdef.l&lt;br /&gt;
	mapdef.r, mapdef.b =&lt;br /&gt;
		currlevel.mapdef.l+currlevel.mapdef.r, currlevel.mapdef.t+currlevel.mapdef.b&lt;br /&gt;
	-- _____  _           __     ________ _____  __ &lt;br /&gt;
	--|  __ \| |        /\\ \   / /  ____|  __ \/_ |&lt;br /&gt;
	--| |__) | |       /  \\ \_/ /| |__  | |__) || |&lt;br /&gt;
	--|  ___/| |      / /\ \\   / |  __| |  _  / | |&lt;br /&gt;
	--| |    | |____ / ____ \| |  | |____| | \ \ | |&lt;br /&gt;
	--|_|    |______/_/    \_\_|  |______|_|  \_\|_|&lt;br /&gt;
	self.player1 = currlevel.player1&lt;br /&gt;
	-- _    _ _    _ _____  &lt;br /&gt;
	--| |  | | |  | |  __ \ &lt;br /&gt;
	--| |__| | |  | | |  | |&lt;br /&gt;
	--|  __  | |  | | |  | |&lt;br /&gt;
	--| |  | | |__| | |__| |&lt;br /&gt;
	--|_|  |_|\____/|_____/ &lt;br /&gt;
	-- function&lt;br /&gt;
	local function clamp(v, mn, mx) return (v&amp;gt;&amp;lt;mx)&amp;lt;&amp;gt;mn end&lt;br /&gt;
	local function map(v, minSrc, maxSrc, minDst, maxDst, clampValue)&lt;br /&gt;
		local newV = (v-minSrc)/(maxSrc-minSrc)*(maxDst-minDst)+minDst&lt;br /&gt;
		return not clampValue and newV or clamp(newV, minDst&amp;gt;&amp;lt;maxDst, minDst&amp;lt;&amp;gt;maxDst)&lt;br /&gt;
	end&lt;br /&gt;
	self.tiny.hud = Sprite.new()&lt;br /&gt;
	-- hud lives&lt;br /&gt;
	self.tiny.hudlives = {}&lt;br /&gt;
	local pixellife&lt;br /&gt;
	for i = 1, self.player1.currlives do&lt;br /&gt;
		pixellife = Pixel.new(0xffff00, 0.8, 16, 16)&lt;br /&gt;
		pixellife:setPosition(8+(i-1)*(16+8), 8)&lt;br /&gt;
		self.tiny.hud:addChild(pixellife)&lt;br /&gt;
		self.tiny.hudlives[i] = pixellife&lt;br /&gt;
	end&lt;br /&gt;
	-- hud health&lt;br /&gt;
	local hudhealthwidth = map(self.player1.currhealth, 0, self.player1.totalhealth, 0, 100, true)&lt;br /&gt;
	self.tiny.hudhealth = Pixel.new(0x00ff00, 2, hudhealthwidth, 8)&lt;br /&gt;
	self.tiny.hudhealth:setPosition(8*1, 8*3.5)&lt;br /&gt;
	self.tiny.hud:addChild(self.tiny.hudhealth)&lt;br /&gt;
	-- hud coins&lt;br /&gt;
	self.tiny.hudcoins = TextField.new(cf2, &amp;quot;COINS: &amp;quot;..self.tiny.numberofcoins)&lt;br /&gt;
	self.tiny.hudcoins:setTextColor(0xff5500)&lt;br /&gt;
	self.tiny.hudcoins:setPosition(8*20, 8*2.3)&lt;br /&gt;
	self.tiny.hud:addChild(self.tiny.hudcoins)&lt;br /&gt;
	--  _____          __  __ ______ _____            &lt;br /&gt;
	-- / ____|   /\   |  \/  |  ____|  __ \     /\    &lt;br /&gt;
	--| |       /  \  | \  / | |__  | |__) |   /  \   &lt;br /&gt;
	--| |      / /\ \ | |\/| |  __| |  _  /   / /\ \  &lt;br /&gt;
	--| |____ / ____ \| |  | | |____| | \ \  / ____ \ &lt;br /&gt;
	-- \_____/_/    \_\_|  |_|______|_|  \_\/_/    \_\&lt;br /&gt;
	-- camera: &amp;#039;content&amp;#039; is a Sprite which holds all your graphics&lt;br /&gt;
	self.camera = GCam.new(layers[&amp;quot;main&amp;quot;], nil, nil, self.player1) -- (content [, anchorX, anchorY]) -- anchor default 0.5, 0.5&lt;br /&gt;
	self.camera:setAutoSize(true)&lt;br /&gt;
	self.camera:setZoom(zoom)&lt;br /&gt;
	self.camera:setBounds(&lt;br /&gt;
		mapdef.l+myappwidth/2/zoom, -- left&lt;br /&gt;
		mapdef.t+myappheight/2/zoom, -- top&lt;br /&gt;
		mapdef.r-myappwidth/2/zoom, -- right&lt;br /&gt;
		mapdef.b-myappheight/2/zoom -- bottom&lt;br /&gt;
	)&lt;br /&gt;
	self.camera:setSoftSize(1.5*32, 2.2*32) -- 1.5*32, 3*32, w, h&lt;br /&gt;
	self.camera:setDeadSize(3*32, 4.4*32) -- 3*32, 5*32, w, h&lt;br /&gt;
	self.camera:setFollow(self.player1.sprite)&lt;br /&gt;
	self.camera:setFollowOffset(0, camfollowoffsety)&lt;br /&gt;
	self.camera:setPredictMode(true)&lt;br /&gt;
	self.camera:setPrediction(0.9) -- 0.8, 0.75, 0.5, number betwwen 0 and 1&lt;br /&gt;
	self.camera:lockPredictionY() -- no prediction on Y axis&lt;br /&gt;
	self.camera:setPredictionSmoothing(4) -- 8, 4, smooth prediction&lt;br /&gt;
--	self.camera:setDebug(true) -- uncomment for camera debug mode&lt;br /&gt;
	--  ____  _____  _____  ______ _____  &lt;br /&gt;
	-- / __ \|  __ \|  __ \|  ____|  __ \ &lt;br /&gt;
	--| |  | | |__) | |  | | |__  | |__) |&lt;br /&gt;
	--| |  | |  _  /| |  | |  __| |  _  / &lt;br /&gt;
	--| |__| | | \ \| |__| | |____| | \ \ &lt;br /&gt;
	-- \____/|_|  \_\_____/|______|_|  \_\&lt;br /&gt;
	layers[&amp;quot;main&amp;quot;]:addChild(layers[&amp;quot;bg&amp;quot;])&lt;br /&gt;
	layers[&amp;quot;main&amp;quot;]:addChild(layers[&amp;quot;bgfx&amp;quot;])&lt;br /&gt;
	layers[&amp;quot;main&amp;quot;]:addChild(layers[&amp;quot;actors&amp;quot;])&lt;br /&gt;
	layers[&amp;quot;main&amp;quot;]:addChild(layers[&amp;quot;fgfx&amp;quot;])&lt;br /&gt;
	layers[&amp;quot;main&amp;quot;]:addChild(layers[&amp;quot;fg&amp;quot;])&lt;br /&gt;
	self:addChild(self.camera)&lt;br /&gt;
	self:addChild(self.tiny.hud)&lt;br /&gt;
	self:addChild(layers[&amp;quot;player1input&amp;quot;])&lt;br /&gt;
	--  _______     _______ _______ ______ __  __  _____ &lt;br /&gt;
	-- / ____\ \   / / ____|__   __|  ____|  \/  |/ ____|&lt;br /&gt;
	--| (___  \ \_/ / (___    | |  | |__  | \  / | (___  &lt;br /&gt;
	-- \___ \  \   / \___ \   | |  |  __| | |\/| |\___ \ &lt;br /&gt;
	-- ____) |  | |  ____) |  | |  | |____| |  | |____) |&lt;br /&gt;
	--|_____/   |_| |_____/   |_|  |______|_|  |_|_____/ &lt;br /&gt;
	self.tiny.tworld:add(&lt;br /&gt;
		-- debug&lt;br /&gt;
--		SDebugPosition.new(self.tiny),&lt;br /&gt;
--		SDebugCollision.new(self.tiny),&lt;br /&gt;
--	 	SDebugShield.new(self.tiny),&lt;br /&gt;
		-- systems&lt;br /&gt;
		SDrawable.new(self.tiny),&lt;br /&gt;
		SAnimation.new(self.tiny),&lt;br /&gt;
		SPlayer1.new(self.tiny, bworld, self.camera),&lt;br /&gt;
		SPlayer1Control.new(self.tiny, self.camera, mapdef, player1inputlayer),&lt;br /&gt;
		SNmes.new(self.tiny, bworld, self.player1),&lt;br /&gt;
		SAI.new(self.tiny, self.player1),&lt;br /&gt;
		SSensor.new(self.tiny, bworld, self.player1),&lt;br /&gt;
		SDoor.new(self.tiny, bworld, self.player1),&lt;br /&gt;
		SMvpf.new(self.tiny, bworld),&lt;br /&gt;
		SCollectibles.new(self.tiny, bworld, self.player1),&lt;br /&gt;
		SProjectiles.new(self.tiny, bworld),&lt;br /&gt;
		SOscillation.new(self.tiny, bworld, self.player1),&lt;br /&gt;
		SCollision.new(self.tiny, bworld, self.player1)&lt;br /&gt;
	)&lt;br /&gt;
	-- _      ______ _______ _  _____    _____  ____  _ &lt;br /&gt;
	--| |    |  ____|__   __( )/ ____|  / ____|/ __ \| |&lt;br /&gt;
	--| |    | |__     | |  |/| (___   | |  __| |  | | |&lt;br /&gt;
	--| |    |  __|    | |     \___ \  | | |_ | |  | | |&lt;br /&gt;
	--| |____| |____   | |     ____) | | |__| | |__| |_|&lt;br /&gt;
	--|______|______|  |_|    |_____/   \_____|\____/(_)&lt;br /&gt;
	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) -- the game loop&lt;br /&gt;
	self:myKeysPressed() -- keys handler&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- game loop&lt;br /&gt;
local timer = 40*8 -- magik XXX&lt;br /&gt;
function LevelX:onEnterFrame(e)&lt;br /&gt;
	if not ispaused then&lt;br /&gt;
		local dt = e.deltaTime&lt;br /&gt;
		if self.player1.restart then&lt;br /&gt;
			if g_currlevel &amp;gt; #self.tiledlevels then&lt;br /&gt;
				timer -= 1&lt;br /&gt;
				if self.camera:getZoom() &amp;lt; 2 then&lt;br /&gt;
					self.camera:setZoom(self.camera:getZoom()+0.4*dt)&lt;br /&gt;
				end&lt;br /&gt;
				if timer &amp;lt;= 0 then&lt;br /&gt;
					self:gotoScene(Win.new())&lt;br /&gt;
					timer = 40*8&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				self:gotoScene(LevelX.new())&lt;br /&gt;
			end&lt;br /&gt;
			self.camera:setPredictionSmoothing(1) -- 4, smooth prediction&lt;br /&gt;
			self.camera:update(dt) -- e.deltaTime, 1/60&lt;br /&gt;
		else&lt;br /&gt;
			self.camera:update(dt) -- e.deltaTime, 1/60&lt;br /&gt;
			self.tiny.tworld:update(dt) -- tiny world (last)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- keys handler&lt;br /&gt;
function LevelX:myKeysPressed()&lt;br /&gt;
	self:addEventListener(Event.KEY_DOWN, function(e) -- KEY_UP&lt;br /&gt;
		if e.keyCode == KeyCode.ESC or e.keyCode == KeyCode.BACK then -- MENU&lt;br /&gt;
			self:gotoScene(Menu.new())&lt;br /&gt;
		elseif e.keyCode == KeyCode.P then -- PAUSE&lt;br /&gt;
			ispaused = not ispaused&lt;br /&gt;
		elseif e.keyCode == KeyCode.R then -- RESTART&lt;br /&gt;
			self.player1.restart = true&lt;br /&gt;
		end&lt;br /&gt;
		-- modifier&lt;br /&gt;
		local modifier = application:getKeyboardModifiers()&lt;br /&gt;
		local alt = (modifier &amp;amp; KeyCode.MODIFIER_ALT) &amp;gt; 0&lt;br /&gt;
		if (not alt and e.keyCode == KeyCode.ENTER) then -- nothing here!&lt;br /&gt;
		elseif alt and e.keyCode == KeyCode.ENTER then -- SWITCH FULLSCREEN&lt;br /&gt;
			ismyappfullscreen = not ismyappfullscreen&lt;br /&gt;
			application:setFullScreen(ismyappfullscreen)&lt;br /&gt;
		end&lt;br /&gt;
	end)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- scenes navigation&lt;br /&gt;
function LevelX:gotoScene(xscene)&lt;br /&gt;
	switchToScene(xscene) -- next scene&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LevelX:init() ===&lt;br /&gt;
==== plugins ====&lt;br /&gt;
Here we initialize our plugins. tiny-ecs is declared as a Class variable (&amp;#039;&amp;#039;self.tiny&amp;#039;&amp;#039;) because we use it outside the &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function. Bump can be local as we only use it in the &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that &amp;#039;&amp;#039;tiny.tworld&amp;#039;&amp;#039; is attached to &amp;#039;&amp;#039;self.tiny&amp;#039;&amp;#039; variable. This makes it much easier to access through the rest of the code in our project.&lt;br /&gt;
&lt;br /&gt;
==== layers ====&lt;br /&gt;
This one is easy :-)&lt;br /&gt;
&lt;br /&gt;
We create several layers which will be laid out on top of each other. The background layer will have all the graphics for the background, etc...&lt;br /&gt;
&lt;br /&gt;
There is a &amp;#039;&amp;#039;player1inputlayer&amp;#039;&amp;#039; which will capture the user input to control the player, it won&amp;#039;t hold any graphics.&lt;br /&gt;
&lt;br /&gt;
==== levels ====&lt;br /&gt;
We use &amp;#039;&amp;#039;&amp;#039;Tiled&amp;#039;&amp;#039;&amp;#039; to build our levels (https://www.mapeditor.org/) and we call the &amp;#039;&amp;#039;TiledLevels Class&amp;#039;&amp;#039; to manage the parsing of the Tiled elements in our game.&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;We dedicate an entire folder for Tiled in our project and we will explain more about it in the next chapter of the tutorial&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;mapdef&amp;#039;&amp;#039; is a table which has the map definition (dimensions), so we can pass it to functions that will require the size of the map for calculations.&lt;br /&gt;
&lt;br /&gt;
==== player1 ====&lt;br /&gt;
The player is an ECS entity we create in the &amp;#039;&amp;#039;TiledLevels Class&amp;#039;&amp;#039;, more on that in the next chapters. We need it here because the HUD and the camera depend on it.&lt;br /&gt;
&lt;br /&gt;
==== hud ====&lt;br /&gt;
I added a simple head up display to the game, so we can see the player current health, number of lives, ...&lt;br /&gt;
&lt;br /&gt;
The same way we attached &amp;#039;&amp;#039;tiny.tworld&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;self.tiny&amp;#039;&amp;#039; variable, we attach some more variables to it. This makes it easier to access those variables.&lt;br /&gt;
&lt;br /&gt;
==== the camera ====&lt;br /&gt;
We use a camera in our game and &amp;#039;&amp;#039;camfollowoffsety&amp;#039;&amp;#039; will offset the camera following the player. It is easier to change it being a variable.&lt;br /&gt;
&lt;br /&gt;
We use a slightly modified version of &amp;#039;&amp;#039;&amp;#039;MultiPain&amp;#039;&amp;#039;&amp;#039;&amp;#039;s (aka rrraptor on Gideros forum) &amp;#039;&amp;#039;&amp;#039;GCam&amp;#039;&amp;#039;&amp;#039; Class for our camera.&lt;br /&gt;
&lt;br /&gt;
Please grab it here &amp;#039;&amp;#039;&amp;#039;[[Media:gcam_beu.lua]]&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(tip: right click and save link as)&amp;#039;&amp;#039;&amp;#039; and put it in the &amp;quot;&amp;#039;&amp;#039;&amp;#039;classes&amp;#039;&amp;#039;&amp;#039;&amp;quot; folder.&lt;br /&gt;
&lt;br /&gt;
We pass the &amp;#039;&amp;#039;mainlayer&amp;#039;&amp;#039; as the content and the player1 to follow.&lt;br /&gt;
&lt;br /&gt;
Using the map definition we set the camera bounds. We also set the soft and the dead size parameters and we tell it to follow the player.&lt;br /&gt;
&lt;br /&gt;
==== order ====&lt;br /&gt;
This is the order of the layers, from bottom to top. We first add the background layer and the other layers on top of it.&lt;br /&gt;
&lt;br /&gt;
==== systems ====&lt;br /&gt;
Once all entities are done, we add the ECS systems. We will see those ECS systems in the coming parts of the tutorial.&lt;br /&gt;
&lt;br /&gt;
==== let&amp;#039;s go ====&lt;br /&gt;
Finally we are ready to run the game loop!&lt;br /&gt;
&lt;br /&gt;
We also listen to some key events to pause the game, go fullscreen, ...&lt;br /&gt;
&lt;br /&gt;
=== LevelX:onEnterFrame &amp;#039;&amp;#039;&amp;#039;THE GAME LOOP&amp;#039;&amp;#039;&amp;#039; ===&lt;br /&gt;
Before the game loop, I declare a local variable: &amp;#039;&amp;#039;timer&amp;#039;&amp;#039; is the time before transitioning to the next level.&lt;br /&gt;
&lt;br /&gt;
If we beat the level then we go to the next level or the &amp;#039;&amp;#039;&amp;#039;Win&amp;#039;&amp;#039;&amp;#039; scene.&lt;br /&gt;
&lt;br /&gt;
Otherwise if the game is not paused we update the camera and the tiny-ecs world. &amp;#039;&amp;#039;&amp;#039;tiny-ecs world&amp;#039;&amp;#039;&amp;#039; runs all the systems (animations, movements, AI, ...). Some systems will be called only once, others every frame per second.&lt;br /&gt;
&lt;br /&gt;
=== LevelX:myKeysPressed ===&lt;br /&gt;
Here we simply listen to some &amp;#039;&amp;#039;&amp;#039;KEY_DOWN Events&amp;#039;&amp;#039;&amp;#039;, that is keys pressed on the keyboard. The key &amp;#039;&amp;#039;ESC&amp;#039;&amp;#039; will go back to the menu, the letter &amp;#039;&amp;#039;P&amp;#039;&amp;#039; will pause the game and when you press &amp;#039;&amp;#039;ALT+ENTER&amp;#039;&amp;#039; you switch the game to fullscreen.&lt;br /&gt;
&lt;br /&gt;
=== LevelX:gotoScene ===&lt;br /&gt;
This is where we transition to the next scene calling the global function &amp;#039;&amp;#039;switchToScene&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== TiledLevels Class ==&lt;br /&gt;
Let&amp;#039;s have a look at how we construct our levels.&lt;br /&gt;
&lt;br /&gt;
The code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Next? ==&lt;br /&gt;
That was quite a lot of work but we coded the heart of our game and we are already nearly done!!&lt;br /&gt;
&lt;br /&gt;
All is left to do is add the actors. Actors will be &amp;#039;&amp;#039;&amp;#039;ECS&amp;#039;&amp;#039;&amp;#039; entites, those entities will have components and systems will control them.&lt;br /&gt;
&lt;br /&gt;
In the next part we deal with our player1 entity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prev.: [[Tuto tiny-ecs 2d platformer Part 3 transitions menu options]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Next: [[Tuto tiny-ecs 2d platformer Part 5 ePlayer1]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[Tutorial - tiny-ecs 2d platformer]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{GIDEROS IMPORTANT LINKS}}&lt;/div&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
</feed>