I've written aI'm new to programming and want to speed up the collision detection in my C++ 2D platformer game engine from scratch in C++. Right now the
Currently, only the player's collision detection that works is for the player. The way I have it setup right now is on each: Every frame a player, the player's update function iterates through every single tile on the level tile (which is pretty largemany) to seeand checks if the player hitbox is collidingcollides with the obstacleit.
I have two questions about this. I'm really a novice at programming, so I may be way off on this, but this seems like a really chunky way of doing it. Is this bad practice? If the level gets large enough, is iterating through this list going to take forever like it seems it should?
My second question builds off of that.: If I start adding for example, enemies into the engine, and give them a similar method for collision detection, can I expect performance drops? I'd like some insight from more experienced people on a better way of setting this up. I would just imagine that having ~20 enemies on the screen all iterating through all possible objects for collision with a list could get slow fast.