So I am creating a rather big project and have eventually ran into the problem of having too many sprites laying on the ground that the player could pick up. They were all so close to each other that it was causing a million polygon checks a minute, mostly because all these items were occupying each other's bounding box. It was considered regular decorative trash (spent items), but I wanted it to be picked up again by the character. This ultimately was the cause of 95%+ CPU use and resulted in a game that quickly becomes unplayable.
So that led me into a quest for efficiency! I will explain the ways I have found to get around this and would love to also hear everyone's feedback on what techniques they have used. My biggest problem is finding a way to not have to go from collision to polygon for dropped items testing EACH OTHER while laying closeby! Some things below are alternative methods and some are ideas for efficiency to the collision detection item pickup.
#1 Using the mouse click or a button to pick up these items to avoid collision detection pickup and have collision on these items turned off.
#2 When the player comes to a stop testing all items for Distance(x1,y1,x2,y2) to do a pickup event.
#3 Turn collision off on items outside of the screen since the player is the only target for these tests.
#4 Delete trash sprites in X seconds, attempt to limit pickup items that can be walked over by making them merge together if they are crossed in bounding boxes (overlapping) the same UID they are the same item and paired into a "stacked" item using a family instance variable.
#5 Stop items that have finished "bouncing" to 0 speed on ground collision and push them outside of the solid that they interact with by sending them back to their last recorded X/Y which saves itself every tick on an instance variable
Thank for any replies ahead of time!
Develop games in your browser. Powerful, performant & highly capable.