Skip to main content
1 of 2
barwin
  • 63
  • 1
  • 3

Performance and collision detection in C++

I've written a 2D platformer game engine from scratch in C++. Right now the only collision detection that works is for the player. The way I have it setup right now is on each frame a player update function iterates through every single tile on the level (which is pretty large) to see if the player hitbox is colliding with the obstacle.

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.

barwin
  • 63
  • 1
  • 3