Shoot The Target GFX problems - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Shoot The Target GFX problems

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

  • IDKIDK Posts: 1,784Member
    : 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]
    :

    Don't clear the screen.
    (remove the cls(RBG_Black) line)
  • Guy_Called_BobGuy_Called_Bob Posts: 3Member

    : 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?

  • IDKIDK Posts: 1,784Member
    :
    : : 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.
  • Guy_Called_BobGuy_Called_Bob Posts: 3Member
    [b][red]This message was edited by Guy_Called_Bob at 2006-10-3 13:29:52[/red][/b][hr]
    : :
    : : : 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.


  • IDKIDK Posts: 1,784Member
    : [b][red]This message was edited by Guy_Called_Bob at 2006-10-3 13:29:52[/red][/b][hr]
    : : :
    : : : : 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.

  • Bera_ParthBera_Parth Posts: 1Member
    Not clearing the screen will serve only if all the things in your screen are stationary. In case if your crosshair (and potentially your target object is moving) this will paint your scene like a brush.
    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. :)
Sign In or Register to comment.