[SDL] Blitting Image With Mouse Click

Jared Maddox absinthdraco at gmail.com
Sun Mar 25 17:41:54 PDT 2012


Looks like some bad timing.

> Date: Sun, 25 Mar 2012 17:13:08 -0700
> From: "GameCoder" <g_andy at live.com>
> To: sdl at lists.libsdl.org
> Subject: Re: [SDL] Blitting Image With Mouse Click
> Message-ID: <1332720788.m2f.32378 at forums.libsdl.org>
> Content-Type: text/plain; charset="iso-8859-1"
>
> OK I think I almost have it done. I just need to figure out how, when the
> user clicks it draws the tower image on the screen. So far, the image is
> already on the screen, before the user clicks. Note: I got rid of the OOP
> code I had.

> stack <int> Towers;
> Tower tower();
> int gtowers;

Once again, what does this do? From looking at this:

>             if(event.type == SDL_MOUSEBUTTONDOWN)
>             {
>                 if(event.button.button == SDL_BUTTON_LEFT)
>                 {
>                     mx = event.button.x;
>                     my = event.button.y;
>
>                     Money -= 200;
>
>                     if(Money != 0)
>                     {
>                         Towers.push(gtowers);
>                     }
>                 }
>             }

It looks like you intend to track the number of elements in Towers
with gtowers, despite the fact that the stack<> template should
provide a size() function for that purpose. Also, I didn't notice
gtowers being modified anywhere. In short, it looks like this bit of
code is completely confused. I advise that you replace

> stack <int> Towers

with:

> stack <Tower> Towers

then do something like:

>             if(event.type == SDL_MOUSEBUTTONDOWN)
>             {
>                 if(event.button.button == SDL_BUTTON_LEFT)
>                 {
>                     mx = event.button.x;
>                     my = event.button.y;
>
>                     Money -= 200;
>
>                     if(Money != 0)
>                     {
>                         Towers.push( Tower( mx, my ) );
>                     }
>                 }
>             }

After that, you'd simply have to iterate over the Towers variable when
you wanted to draw them.



More information about the SDL mailing list