   2D Collision Implementation Problem
  I read the 2D collision detection article here and I used that as a template in creating my own.  Right now, it's only detecting rectangles, but I'll eventually get it down to pixels.The question is, when to detect collision?  Do I do it within the environment it's in?  Do I do it when it moves?  When?  Can someone provide me of an example of actually implementing the collision detection?I'm trying to find out what place it should be in and at what time should the detection occur.Thanks.   
  In order to detect collision, you check each frame to see if it has happened and if it has, then you take action (I'm sure you read about that in the actual article, though). So you check in the game loop because if you checked outside of the game loop, it would not work because it would only check it once and never again. I am not sure what sort of example you would like because, judging by your post, you already understand how to actually check for collision. Also, if you are already trying to check collision you must have an understanding of the structure of a game and the game loop etc..   ;  When something moves would be a logical time, yeah. How else will it know if it doesn't run into some obstacles?After all, if something doesn't move, it won't collide with anything if it didn't already. Unless something else crashes into it, but then that object should check for it, because it moves. ;)   ;  Putting it in more concrete terms, I place the check in the move() function.  That means I have to get every single object on the screen and check if any of them have a collision with the one I'm checking.So pseudocode will be something like this: void move(){// Move in the x-direction.// Checks if it collided with the boundaries.// Get all the objects on screen and checks for each collision.vector<Locatable*> sprites = get_objects();for ( unsigned int i = 0; i < sprites.size(); ++i ) {// Makes sure it's not checking itself.if ( (Locatable)sprites.at( i ) == this ) {continue;}if ( check_collision( this, (Locatable)sprites.at( i ) ) {// Do something...}}// Do the exact same thing with Y...} Please, correct me if that logic is wrong.   ;  Doesn't look wrong to me. Have you tested it already?Anyway, if things are running slow, then you should think about adding some optimizations, such as only checking against objects that are nearby (spatial partitioning helps for such purposes, using a quadtree is a common method), or only checking against objects that are actually relevant (a moving enemy doesn't need to do collision checks against coins he doesn't pick up, right?).Just don't put this code in multiple move functions, because then you're duplicating functionality. If both an Enemy and Player perform these checks, then put it in a seperate function that both can call (but keep differences in reaction in mind, e.g. the enemy that doesn't pick up coins and such).As for the boundaries, aren't those just collidable area's as well, just like walls and floors in your levels? ;)   