I am using SDL and a booster called QuickCG by Lode Vandevenne. I am trying to do something simple, drawing a cross hairs, a target, and bullet holes in paint. The problem is that I can't find a way to update the screen and keep the bullet holes. The code for the drawing functions is as follows:
[CODE]
void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, scr, &dest);
}
void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, scr, &dest);
}
void DrawBulletHoles()
{
int mouseX, mouseY;
getMouseState(mouseX, mouseY);
DrawIMG(bullet, mouseX, mouseY);
SDL_Flip(scr);
}
void DrawScene()
{
int mouseX, mouseY;
bool RMB, LMB;
cls(RGB_Black);
DrawIMG(target, TargetX, TargetY);
getMouseState(mouseX, mouseY, LMB, RMB);
DrawIMG(gun, mouseX, mouseY);
if(LMB == true)
{
DrawBulletHoles();
}
SDL_Flip(scr);
}
[/CODE]
Comments
:
: [CODE]
: void DrawIMG(SDL_Surface *img, int x, int y)
: {
: SDL_Rect dest;
: dest.x = x;
: dest.y = y;
: SDL_BlitSurface(img, NULL, scr, &dest);
: }
:
: void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2)
: {
: SDL_Rect dest;
: dest.x = x;
: dest.y = y;
: SDL_Rect dest2;
: dest2.x = x2;
: dest2.y = y2;
: dest2.w = w;
: dest2.h = h;
: SDL_BlitSurface(img, &dest2, scr, &dest);
: }
:
:
: void DrawBulletHoles()
: {
: int mouseX, mouseY;
: getMouseState(mouseX, mouseY);
: DrawIMG(bullet, mouseX, mouseY);
: SDL_Flip(scr);
: }
:
: void DrawScene()
: {
: int mouseX, mouseY;
: bool RMB, LMB;
: cls(RGB_Black);
: DrawIMG(target, TargetX, TargetY);
: getMouseState(mouseX, mouseY, LMB, RMB);
: DrawIMG(gun, mouseX, mouseY);
: if(LMB == true)
: {
: DrawBulletHoles();
: }
: SDL_Flip(scr);
: }
: [/CODE]
:
Don't clear the screen.
(remove the cls(RBG_Black) line)
: Don't clear the screen.
: (remove the cls(RBG_Black) line)
I fixed it a different way. But, another problem has arisen! I use two arrays to hold all the bullet hole's X & Ys. But it prints them at the edge of the screen [b]and[/b] where they should be. It is also extremely laggy for a small program. Should I limit the number of refreshes a second?
: : Don't clear the screen.
: : (remove the cls(RBG_Black) line)
:
: I fixed it a different way. But, another problem has arisen! I use two arrays to hold all the bullet hole's X & Ys. But it prints them at the edge of the screen [b]and[/b] where they should be. It is also extremely laggy for a small program. Should I limit the number of refreshes a second?
:
:
No, you shouldn't remove them at the first point.
Why should you remove them, when the next thing you do is to repaint them?
Just don't clear the screen.
: :
: : : Don't clear the screen.
: : : (remove the cls(RBG_Black) line)
: :
: : I fixed it a different way. But, another problem has arisen! I use two arrays to hold all the bullet hole's X & Ys. But it prints them at the edge of the screen [b]and[/b] where they should be. It is also extremely laggy for a small program. Should I limit the number of refreshes a second?
: :
: :
:
: No, you shouldn't remove them at the first point.
: Why should you remove them, when the next thing you do is to repaint them?
:
: Just don't clear the screen.
:
When I don't the cursor prints and doesn't go away. What I mean is that if cursor was at x and is moved to y, it shows it at x and y.
: : :
: : : : Don't clear the screen.
: : : : (remove the cls(RBG_Black) line)
: : :
: : : I fixed it a different way. But, another problem has arisen! I use two arrays to hold all the bullet hole's X & Ys. But it prints them at the edge of the screen [b]and[/b] where they should be. It is also extremely laggy for a small program. Should I limit the number of refreshes a second?
: : :
: : :
: :
: : No, you shouldn't remove them at the first point.
: : Why should you remove them, when the next thing you do is to repaint them?
: :
: : Just don't clear the screen.
: :
:
: When I don't the cursor prints and doesn't go away. What I mean is that if cursor was at x and is moved to y, it shows it at x and y.
:
:
Then do as I suggested in my first reply.
There is another way.
Use a buffer.
Here is a hint. Whenever a hit occurs you can calculate the position of bullet-hole w.r.t. the parent body i.e. your target in this case. You can hold the location of bullet-holes in a static array or linked list of struct bullethole_pos2i{ int x, int y}.
Hope this will work well.