Skip to main content
GameDev.net gamedev.net
🔒 Locked

need help SDL EVENTS!

Started by AppleMade Apr 16, 2012 at 10:50 AM 5 replies 2.2k views
Original Post
AppleMade
AppleMade
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..
Wooh
Wooh
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
AppleMade
AppleMade
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..
rip-off
rip-off
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.
AppleMade
AppleMade
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]
SimonForsman
SimonForsman
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)
[size="1"]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!
albertino
albertino
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 [color="#000088"]if[color="#666600"]( [color="#666600"]([color="#000000"] x [color="#666600"]>[color="#000000"] box[color="#666600"].[color="#000000"]x [color="#666600"]) [color="#666600"]&& [color="#666600"]([color="#000000"] x [color="#666600"]<[color="#000000"] box[color="#666600"].[color="#000000"]x [color="#666600"]+[color="#000000"] box[color="#666600"].[color="#000000"]w [color="#666600"]) [color="#666600"]&& [color="#666600"]([color="#000000"] y [color="#666600"]>[color="#000000"] box[color="#666600"].[color="#000000"]y [color="#666600"]) [color="#666600"]&& [color="#666600"]([color="#000000"] y [color="#666600"]<[color="#000000"] box[color="#666600"].[color="#000000"]y [color="#666600"]+[color="#000000"] box[color="#666600"].[color="#000000"]h [color="#666600"]) [color="#666600"])
[color="#666600"]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)
[color="#000088"]void [color="#660066"]Button[color="#666600"]::[color="#000000"]handle_events[color="#666600"](int box.x, int box.y, int box.w, int box.h)

hope helps
regards

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.