We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Guys and gals,
I've been searching for a solution to my question in the forums – because I'm pretty sure I'm not the first person to ask this – but obviously I'm not using the right keywords, because I've not yet found any answers.
This is my hypothetical setup: Let's say I have a few thousand white ellipses scattered randomly on the screen and I want to turn every object fill-color within a 100px radius of the mouse to red. The working and obvious solution is to loop through EVERY object in play and use dist() to determine it's distance to the mouse and then act accordingly. Which does work fine, but slows down considerably the more objects are on the screen and the more complex the behaviours of these objects become.
Now I'm thinking that it ought to be possible to limit the actual calculations to just a fraction of the total objects, create sort of a "preselection" I you want, and thus forego the dist()-check on all object. But that's where I'm stuck. I know there are optimisation processes in programming to prevent ALL calculations happening at ALL time (like chunks in Minecraft) but I can't find the right terms to start reading into this topic. I've thought about creating quadrants, then checking which object is in which quadrant and then just apply calculations to the objects in the same quadrant as the mouse currently is. But my code always turns out to at some point require the same calculations across all objects. I'm stumped and would be grateful, not for a code solution, but on pointers on where I could read about this topic/which keywords I should be searching for. (Given the facts, that what I'm imagining is in fact a thing).
Also, I'm not specifically only trying to turn white ellipses red, that's just a simple example. I'd like to know how to set up a system which does the selection of a subset of objects, no matter what the actual operations then might be.