• Advertisement
Sign in to follow this  

need help SDL EVENTS!

This topic is 2100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
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]

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement