Algorithm for Direction Change upon Collision

Alex Tweedly alex at tweedly.org
Sat Nov 9 18:18:03 CET 2013


Hi Scott,

Although I'd agree with your advice in general, I'd caution against 
making point 2 too strongly. I fully agree about
    "Don't underestimate the speed of text lists ..."
but not with
    "... avoid using arrays in code that is repeated in a loop"

I re-wrote your code using an array rather than a text list, and there 
was no discernible difference in speed. Even moving up to 200 particles, 
I was consistently getting the same timings for each of the two methods 
(they both varied between 48 and 54 ms per cycle, on a MacBook Pro).

The speed of your code came from careful use of loopObject and 
innerObject (and your other points) - not from discarding the use of arrays.


btw   You have a minor bug - in the inner loop, the first line should be
     if item 1 of loopObject then
rather than
     if item  of collisionlist then


-- Alex.

On 09/11/2013 05:36, RunRevPlanet wrote:
> Hi Ender,
>
> Your original post about particles, made be wonder about how many moving images
> LiveCode can support. There is a stack here:
>
> http://livecodegamedeveloper.com/download/100-Particle-Test.livecode
>
> That solves the problem of the "trembling clumps" and handles 100 particles and
> possibly more depending on the fps you are aiming for. (This is on an older
> desktop PC, I haven't tried it on a mobile device.) I was also going for a more
> random effect where the particles go every which way. It was done on LiveCode
> Community 6.1.2.
>
> The "tricks" to this demo are:
>
> 1. Don't even try real physics, if it is just for visual effect, near enough is
> good enough.
>
> 2. Don't underestimate the speed of text lists in LiveCode. When the number of
> items is measured in the hundreds, avoid using arrays in any code that is
> repeated in a loop.
>
> 3. Somewhat paradoxically, more code in the loop that does the screen updating
> is actually faster if the logic used is more efficient.
>
> Note this stack has the acceleratedRendering set to false. On some platforms
> setting it to true may make the animation smoother.
>
> --
> Scott McDonald
> "Components, Controls, Tools and Resources for LiveCode"
> www.runrevplanet.com
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list