<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Quad Tree gives 3 x fps for collision detection of 180 sprites]]></title><description><![CDATA[<p dir="auto">Maybe you stumbled upon collision detection limits too.</p>
<p dir="auto">A Quad Tree is a kind of a linked list, where every node has 4 children. Every children stores sprites in one quadrant of the screen. And every quadrant splits up again in four quadrants and so on, until there are not more than k sprites in one node (visually in one field). Here I defined k as 3.<br />
If the tree has been built, it is possible to only check each field that contains more than one sprite if it collides with one of the other sprites, in the same field.</p>
<p dir="auto">This is my first draft of a Quad Tree and it's still "work in progress". <strong>Your help is also much appreciated in improving this code.</strong></p>
<p dir="auto">Share code:  <strong>9M2P3MNDN8</strong> (live)</p>
<p dir="auto">Thats how far I was able to push this:<br />
Collision checks of <strong>180 sprites at &gt; 30 fps</strong> (which is the minmal frame rate I try to keep). Checking the collisions one by one (180 x 180 checks), I got 10 fps.</p>
<p dir="auto"></p><blockquote class="content twitter-tweet" lang="en"><a href="https://twitter.com/spikeych/status/1414004765428621312?s=20"></a></blockquote><p></p>
<p dir="auto">Maybe I can get around with that, if I handle moving and not moving objects differently in my game <a href="https://fuzearena.com/forum/topic/1445/last-worm-creeping-enhancing-the-gameplay/4" target="_blank" rel="noopener noreferrer">Last Worm Creeping</a> I try to improve.</p>
]]></description><link>http://fuzearena.com/forum//topic/1746/quad-tree-gives-3-x-fps-for-collision-detection-of-180-sprites</link><generator>RSS for Node</generator><lastBuildDate>Mon, 09 Mar 2026 14:38:03 GMT</lastBuildDate><atom:link href="http://fuzearena.com/forum//topic/1746.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 11 Jul 2021 00:24:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Fri, 30 Jul 2021 21:45:05 GMT]]></title><description><![CDATA[<p dir="auto">I gave this a look and I found an easy improvement as it is now is to increase the node capacity to around 9 or 10. It seems to perform much better than 3. After that it starts to bottleneck somewhere else.</p>
]]></description><link>http://fuzearena.com/forum//post/16390</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16390</guid><dc:creator><![CDATA[Devieus]]></dc:creator><pubDate>Fri, 30 Jul 2021 21:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Fri, 16 Jul 2021 19:05:11 GMT]]></title><description><![CDATA[<p dir="auto">Yeah, that's one way 'ref' does not work. Currently, the thing passed to a ref argument needs to be a simple variable for changes to it to become visible, no array element, no struct element, no array slice. Go with a big array to store your nodes, pass around and store indices into it. That seems to be the only way to manage complex mutable data structures right now.</p>
]]></description><link>http://fuzearena.com/forum//post/16303</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16303</guid><dc:creator><![CDATA[Z-Mann]]></dc:creator><pubDate>Fri, 16 Jul 2021 19:05:11 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Fri, 16 Jul 2021 15:16:33 GMT]]></title><description><![CDATA[<p dir="auto">I also tried this without success:</p>
<pre><code>struct NODE_TYPE
   NODE_TYPE children = []
   int id
endstruct

NODE_TYPE node
node.id = 0
node.children[0] = create()

function create()
   NODE_TYPE node
return node

// same changeId() function and test as above
</code></pre>
<p dir="auto">shows also <code>1</code>. I am wondering if I miss something.</p>
]]></description><link>http://fuzearena.com/forum//post/16302</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16302</guid><dc:creator><![CDATA[spikey]]></dc:creator><pubDate>Fri, 16 Jul 2021 15:16:33 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Fri, 16 Jul 2021 14:58:18 GMT]]></title><description><![CDATA[<p dir="auto">Ok, if I want to build an insert and remove function, I will have to pass indexes to a major array instead of references, I guess.</p>
]]></description><link>http://fuzearena.com/forum//post/16301</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16301</guid><dc:creator><![CDATA[spikey]]></dc:creator><pubDate>Fri, 16 Jul 2021 14:58:18 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Fri, 16 Jul 2021 14:36:47 GMT]]></title><description><![CDATA[<p dir="auto">The second problem is I cannot use recursion to pass references to arrays: this is an example how I was hoping to be able to change an id of a linked element (in my project I would have used this to remove and insert elements in the middle of the tree)</p>
<pre><code>node = [.children = [], .id = 0]
node.children[0] = [.children = [], .id = 1]

function changeId(ref node)
   if len(node.children) == 0 then
      node.id = 888
   else      
      changeId(node.children[0])
   endif
return void

print(node.children[0].id)
update()
sleep(10)
</code></pre>
<p dir="auto">This always shows <code>1</code> and never <code>888</code>.</p>
]]></description><link>http://fuzearena.com/forum//post/16300</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16300</guid><dc:creator><![CDATA[spikey]]></dc:creator><pubDate>Fri, 16 Jul 2021 14:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Fri, 16 Jul 2021 11:05:15 GMT]]></title><description><![CDATA[<p dir="auto">I need an <code>insert()</code> function for the Quad Tree, but run into a huge problem: one element of a custom array attribute of a sprite cannot be changed, as far I can tell. e.g.:</p>
<pre><code>node = createSprite()
node.customAttribute = [1, 2, 3]
node.customAttribute[0] = 8
</code></pre>
<p dir="auto">returns the error <code>Attempted to index non-array type.</code><br />
Same for adding an element <code>node.customAttribute[3] = 4</code></p>
<p dir="auto">I check now if I can change the code to always set the whole array at once.</p>
]]></description><link>http://fuzearena.com/forum//post/16295</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16295</guid><dc:creator><![CDATA[spikey]]></dc:creator><pubDate>Fri, 16 Jul 2021 11:05:15 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Mon, 12 Jul 2021 22:39:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://fuzearena.com/forum//uid/606">@vinicity</a> Sure I can have a look. I have something that needs to be done first, but I will work hard to get that done this week. Only after this, it will show, if its practical.</p>
]]></description><link>http://fuzearena.com/forum//post/16244</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16244</guid><dc:creator><![CDATA[spikey]]></dc:creator><pubDate>Mon, 12 Jul 2021 22:39:34 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Mon, 12 Jul 2021 22:27:18 GMT]]></title><description><![CDATA[<p dir="auto">I downloaded your demo, <a class="plugin-mentions-user plugin-mentions-a" href="http://fuzearena.com/forum//uid/360">@spikey</a>, and it’s very interesting and quite impressive.</p>
<p dir="auto">I came to think about my old light based sneak game. Do you think your technique could be used in that one as well?<br />
I just shared it (so still pending), but maybe you could take a look if you have the time?</p>
<p dir="auto">Download ID: <code>NN8AVRND5C</code></p>
]]></description><link>http://fuzearena.com/forum//post/16241</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16241</guid><dc:creator><![CDATA[vinicity]]></dc:creator><pubDate>Mon, 12 Jul 2021 22:27:18 GMT</pubDate></item><item><title><![CDATA[Reply to Quad Tree gives 3 x fps for collision detection of 180 sprites on Sun, 11 Jul 2021 01:08:34 GMT]]></title><description><![CDATA[<p dir="auto">Wow, that’s a massive improvement!</p>
]]></description><link>http://fuzearena.com/forum//post/16219</link><guid isPermaLink="true">http://fuzearena.com/forum//post/16219</guid><dc:creator><![CDATA[PickleCatStars]]></dc:creator><pubDate>Sun, 11 Jul 2021 01:08:34 GMT</pubDate></item></channel></rss>