#### Archived

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

# Pixel Collisions

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

## 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 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

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×