Hi Phantom,
Just FYI the SDL list is not used for programming techniques so much, it’s
mostly for help with sdl specific questions. A much better list for that is
at gameprogrammer.com.
But yes, there is a much better way than doing what you are doing!
Instead of checking every x and y of a surface to see if it matches a
particle’s x and y, do this:
If((particle.x>=surface->clip_rect.x)&&(particle.x<=(surface->clip_rect.x+su
rface->clip_rect.w))&&
(particle.y>=surface->clip_rect.y)&&(particle.y<=(surface->clip_rect.y+surfa
ce->clip_rect.h)))
{
//do something
}
This way instead of testing each and every pixel on the surface, you are
just checking to see mathematically if the pixel is inside the other surface
or not._____
From: sdl-bounces+atrix2=cox.net@libsdl.org
[mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Phantom Lord
Sent: Monday, July 03, 2006 5:19 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: [SDL] Fast Way To Check If Certain Pixel is Inside Certain Surface
Hi, i’m working on a particle engine (pixel-based, for now) and i’d
implement the following code for checking if the pixel is inside that
Certain Surface:
for(int i=surface->clip_rect.x; iclip_rect.w; i++)
for(int j=surface->clip_rect.y; jclip_rect.h; j++)
if(particle.x == i && particle.y == j) do something.
But this carried me bigs “delays” whenever its executed.
Has somebody a better way to doing it?.
Thx, and sorry for my english, not native.
–
Leandro Ostera,
Caelis Interactive