Sign in to follow this  
AppleMade

need help SDL EVENTS!

Recommended Posts

AppleMade    100
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..

Share this post


Link to post
Share on other sites
Wooh    1088
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

Share this post


Link to post
Share on other sites
AppleMade    100
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..

Share this post


Link to post
Share on other sites
rip-off    10976
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.

Share this post


Link to post
Share on other sites
AppleMade    100
code-(events function)
[code]
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++;
}
}

}
}
[/code]

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]

Share this post


Link to post
Share on other sites
SimonForsman    7642
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)

Share this post


Link to post
Share on other sites
albertino    101
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][color="#666600"]([/color] [color="#666600"]([/color][color="#000000"] x [/color][color="#666600"]>[/color][color="#000000"] box[/color][color="#666600"].[/color][color="#000000"]x [/color][color="#666600"])[/color] [color="#666600"]&&[/color] [color="#666600"]([/color][color="#000000"] x [/color][color="#666600"]<[/color][color="#000000"] box[/color][color="#666600"].[/color][color="#000000"]x [/color][color="#666600"]+[/color][color="#000000"] box[/color][color="#666600"].[/color][color="#000000"]w [/color][color="#666600"])[/color] [color="#666600"]&&[/color] [color="#666600"]([/color][color="#000000"] y [/color][color="#666600"]>[/color][color="#000000"] box[/color][color="#666600"].[/color][color="#000000"]y [/color][color="#666600"])[/color] [color="#666600"]&&[/color] [color="#666600"]([/color][color="#000000"] y [/color][color="#666600"]<[/color][color="#000000"] box[/color][color="#666600"].[/color][color="#000000"]y [/color][color="#666600"]+[/color][color="#000000"] box[/color][color="#666600"].[/color][color="#000000"]h [/color][color="#666600"])[/color] [color="#666600"]) [/color]
[color="#666600"]box.x box.y box.w box.h [/color]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] [color="#660066"]Button[/color][color="#666600"]::[/color][color="#000000"]handle_events[/color][color="#666600"](int box.x, int box.y, int box.w, int box.h)[/color]

hope helps
regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this