Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

need help SDL EVENTS!

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 AppleMade   Members   

100
Like
0Likes
Like

Posted 16 April 2012 - 04:50 AM

hey..
i wanna know how to handle sdl events..more precisely the "mousebutton" thing.
for example--
wen i click frst time an image appears...i want some other image next time i click,and thrd image nxt time and so on..,
pls help asap..really will be thankful plssss..

#2 Wooh   Members   

1088
Like
0Likes
Like

Posted 16 April 2012 - 05:02 AM

LazyFoo has a tutorial about mouse events that you can read to get an idea of how it works. http://lazyfoo.net/SDL_tutorials/lesson09/index.php

#3 AppleMade   Members   

100
Like
0Likes
Like

Posted 21 April 2012 - 08:45 AM

i read d tutorial but m not able to get anything on secnd click..i tried using a seperate counter whose value increments evrytime downbutton is clicked,,but it is not working..

#4 rip-off   Moderators   

10926
Like
0Likes
Like

Posted 21 April 2012 - 10:44 AM

Define "it is not working". It fails to compile? The program crashes during startup? The program does something incorrect, or nothing, at runtime?

Post your code, and a complete description of the expected and actual behaviour. Post any compile time or run time error messages that you are getting. Be accurate.

Also, please use the best grammar, punctuation, capitalisation and spelling that you can. This is not real time chat, nor are the number of characters you use at a premium. Spending a few minutes carefully preparing your post will get you more and better responses. People will be more willing to respond in detail to someone who is seen as putting effort into their posts.

#5 AppleMade   Members   

100
Like
0Likes
Like

Posted 21 April 2012 - 01:17 PM

code-(events function)
void Button::handle_events()
{

    int x = 0, y = 0;
    int count=0;

   while( event.type == SDL_MOUSEBUTTONDOWN )
    {

        if( event.button.button == SDL_BUTTON_LEFT )
        {

            x = event.button.x;
            y = event.button.y;


            if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
            {
              if(count==0){
                           clip = &clips[ CLIP_NUMBER1];     //shows number 1
                           count++;
                           }
              else{
                    clip = &clips[ CLIP_NUMBER2];          //shows number 2
                           count++;
                           }    
            }

        }
    }

ERROR-compiles fine,but when output screen shows up and i click it,nothing happens and says "not responding"..

ps-i am in learning process so there might be some novice mistake,thanks for your time.

[mod edit: adding code tags -- rip-off]

#6 SimonForsman   Members   

7640
Like
0Likes
Like

Posted 21 April 2012 - 01:53 PM

while( event.type == SDL_MOUSEBUTTONDOWN )

that causes an infinite loop as event never changes within the function.

You are also initializing the counter to 0 each time the function is called (Which is probably not what you want to do)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 albertino   Validating   

101
Like
0Likes
Like

Posted 23 April 2012 - 04:32 AM

i am not very good at handling event too but if i can answer what you are trying to create it is a button so if your function it is insert in a pollevent chain will work but i see something strange thing in it if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
box.x box.y box.w box.h are the coordinates of your rectangle but where you define in the function?
should be somewhere
SDL_Rect box
box.x=......
box.y=....
box.w=....
box.h=.....

alternatevly (never tryied you might try to import from somewhereelse very bad in my opinion)
void Button::handle_events(int box.x, int box.y, int box.w, int box.h)

hope helps
regards




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.