<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Market Run</title>
    <description>The latest articles on DEV Community by Market Run (@marketrunengine).</description>
    <link>https://dev.to/marketrunengine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4233681%2F32a350c7-3786-42bc-97a5-e961857899e8.png</url>
      <title>DEV Community: Market Run</title>
      <link>https://dev.to/marketrunengine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marketrunengine"/>
    <language>en</language>
    <item>
      <title>Why the kiosk hid the courier in this JavaScript game</title>
      <dc:creator>Market Run</dc:creator>
      <pubDate>Sun, 08 Nov 2026 14:56:48 +0000</pubDate>
      <link>https://dev.to/marketrunengine/why-the-kiosk-hid-the-courier-in-this-javascript-game-43pk</link>
      <guid>https://dev.to/marketrunengine/why-the-kiosk-hid-the-courier-in-this-javascript-game-43pk</guid>
      <description>&lt;p&gt;AI can generate a working game before you understand its engine. When a character suddenly disappears behind a kiosk, knowing which part of the code to inspect becomes useful.&lt;/p&gt;

&lt;p&gt;In Market Run, the courier below is standing in front of a fruit kiosk. You can see their shoes, but the rest of the character is hidden. Before changing the movement or collision code, freeze the two objects and inspect how the engine draws them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F977xitkqdk2bnyxg9ctb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F977xitkqdk2bnyxg9ctb.png" alt="Two renders of the same scene. On the left the kiosk hides the courier. On the right the courier appears in front." width="720" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The blue dot marks the courier's feet. The red dot marks the kiosk's ground anchor. Both dots stay in the same place between these pictures. The draw order changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Predict the next frame
&lt;/h2&gt;

&lt;p&gt;Canvas paints a sprite over the pixels already on the canvas. In this scene, the courier's feet are at screen y = 188 and the kiosk's ground anchor is at y = 168. Screen y increases downward. The courier's feet are lower on the screen, so the courier should appear in front.&lt;/p&gt;

&lt;p&gt;Consider this deliberately reversed comparator, with the courier as &lt;code&gt;a&lt;/code&gt; and the kiosk as &lt;code&gt;b&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;168 - 188&lt;/code&gt; gives &lt;code&gt;-20&lt;/code&gt;. The courier sorts first. The engine draws the courier, then paints the kiosk over them. The shoes stick out beyond the kiosk artwork, which explains the left-hand picture.&lt;/p&gt;

&lt;p&gt;Now use the rule from the working depth lab:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foot&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comparison now gives &lt;code&gt;+20&lt;/code&gt;. The kiosk draws first and the courier draws last. The world positions have not changed; which pixels survive the frame has changed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;foot&lt;/code&gt; is the projected ground anchor, not the top edge of the image. That distinction matters because a tall kiosk and a short character can have very different image heights while standing on the same ground plane.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check your explanation with another position
&lt;/h2&gt;

&lt;p&gt;Move the courier behind the kiosk, to screen y = 148. Keep the kiosk at 168. Predict which object should draw last before running the scene.&lt;/p&gt;

&lt;p&gt;The ascending sort draws the courier first and the kiosk second. Hard-coding the player to draw last would fix the first picture and break this one.&lt;/p&gt;

&lt;p&gt;This is a useful debugging routine when working with AI-generated code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Describe the visible failure precisely.&lt;/li&gt;
&lt;li&gt;Freeze unrelated state, such as movement.&lt;/li&gt;
&lt;li&gt;Identify the rule that could explain the frame.&lt;/li&gt;
&lt;li&gt;Predict the result of one change.&lt;/li&gt;
&lt;li&gt;Make that change and repeat the same experiment.&lt;/li&gt;
&lt;li&gt;Try a second case that could prove your explanation wrong.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The comparator changes visibility. It does not make a solid kiosk passable, change the character's position or fix collision detection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this rule stops being enough
&lt;/h2&gt;

&lt;p&gt;Sorting whole sprites works for this small ground-plane example. A canopy that must cover a character while its base stays behind them may need separate draw pieces. Bridges, multiple floors and complex overlapping geometry need more explicit rendering rules.&lt;/p&gt;

&lt;p&gt;The useful habit is to connect a rule in the code to an observable result, then recognize the cases the rule does not cover.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://market-run-sales.netlify.app/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=first_sale&amp;amp;utm_content=day01#lesson" rel="noopener noreferrer"&gt;Try the free interactive kiosk lesson and switch the draw order yourself.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  From one rendering rule to a reusable engine
&lt;/h2&gt;

&lt;p&gt;This example is part of our &lt;em&gt;Build a Game Engine from Scratch in JavaScript&lt;/em&gt; book and source bundle, published under the Market Run brand. It is for people who already know basic JavaScript and are new to game development.&lt;/p&gt;

&lt;p&gt;The goal is to understand the engine underneath a game: how it reads input, advances time, checks movement, sorts sprites and draws a frame. That understanding gives you a way to inspect and change code produced by AI.&lt;/p&gt;

&lt;p&gt;The current &lt;strong&gt;$19 bundle includes all four PDF books, matching source code and three playable games&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Market Run:&lt;/strong&gt; a delivery game for learning the engine foundations. Start with Edition 2 and its six browser labs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Outpost Defense:&lt;/strong&gt; a tower-defense game that applies the shared engine to combat, waves and resources in Edition 3.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signal Runner:&lt;/strong&gt; a platformer that adds jump feel, moving platforms, hazards and checkpoints in Edition 4.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edition 1:&lt;/strong&gt; the original, smaller Market Run book and source, included for comparison.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Edition 4's combined source contains all three games using one shared engine directory, with each game's rules kept separate. Use each book with its matching source archive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://market-run-sales.netlify.app/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=first_sale&amp;amp;utm_content=day01#games" rel="noopener noreferrer"&gt;Play all three games and read the free sample chapter before deciding whether the bundle fits you.&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: this article promotes our own book and source bundle. It was drafted with AI assistance; the code explanation was checked against the shipped depth lab, and the images come from the running example.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>gamedev</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
