Archived

This topic is now archived and is closed to further replies.

Pixel Collisions

This topic is 5746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I''m making a game with worms-style terrains (basically a map of pixels) My engine can detect pixels okay, but whenever I put in any code to handle collisions, it doubles the frame rate! Here''s my detection code:
  
for(AnimListIt1 = AnimList.begin(); AnimListIt1 != AnimList.end(); ++AnimListIt1)
	{
		for(int y = CameraY; y < CameraY + 600; y++)
		{
			for(int x = CameraX; x < CameraX + 800; x++)
			{
				if(!(MyArray[x][y]))
				{
					if(!(AnimListIt1->Left > x || AnimListIt1->Right < x || AnimListIt1->Top > y || AnimListIt1->Bottom < y))
					{
					//AnimListIt1->y -= AnimListIt1->yv;

					AnimListIt1->yv = 0;
					//AnimListIt1->x -= AnimListIt1->xv;

					//AnimListIt1->xv = 0;     

					//	if( (AnimListIt1->Bottom - y) < 8)	

					//		AnimListIt1->y = y - AnimListIt1->BBound;

					//	if( (y - AnimListIt1->Top) < 8)

					//		AnimListIt1->y = y;

					//	if( (AnimListIt1->Right - x) < 8)

					//		AnimListIt1->x = x - AnimListIt1->RBound;

					//	if( (x - AnimListIt1->Left) < 8)

					//		AnimListIt1->x = x;

					}
				}
			}
		}
	}

  
Putting collsion-handling code in there double the framerate EVEN WHEN I"M NOT COLLIDING with a pixel. This doesn''t make any sense to me, sense it should just be skipping over that code anyway. Does anyone know what''s wrong? Is there a way that I can optimize this?

Share this post


Link to post
Share on other sites
It looks like your checking all the pixels, why not just check the pixels within the animation boundarys (assuming myarray is the pixel map).

Rather than:

NumberOfAnimations * 800*600

Do:

NumberOfAnimations * AnimationWidth * AnimationHeight


,Jay

Share this post


Link to post
Share on other sites