Skip to content

Optimize isTouchingDrawables? #18

@DNin01

Description

@DNin01

Update: See #18 (comment)


As you know, TurboWarp is all about speeding up Scratch projects, so when I saw a function, isTouchingDrawables, with this comment...

// This is an EXTREMELY brute force collision detector, but it is
// still faster than asking the GPU to give us the pixels.

...I saw potential for improvement.

If I'm understanding the code right, Scratch checks for collisions between every single pixel to be sure that the sprites appear to be precisely touching each other. This can slow things down a lot when overused.

Instead of colliding individual pixels, combining groups of pixels to form rectangles, as shown in the video below, would reduce the number of regions that need to be accounted for, increasing performance in the long run.

optimized.touching.detector.webm

Some projects may see performance improvements of over 10x or even 50x in circumstances that would normally cause lag spikes.

@GarboMuffin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions