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..
6 replies to this topic
Ad:
#2 Members - Reputation: 277
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
#4 Moderators - Reputation: 5034
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.
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 Members - Reputation: 100
Posted 21 April 2012 - 01:17 PM
code-(events function)
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]
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 Members - Reputation: 3708
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)
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!
The voices in my head may not be real, but they have some good ideas!
#7 Members - Reputation: 100
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
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






