SFML community forums
Help => System => Topic started by: darekg11 on October 03, 2010, 09:24:14 pm
-
Okey, I need something like this:
When You click at the area of string then program starts OGG file and after 3 seconds quit.
I already spent 3hours trying to get it to work.
Event.type == sfvEventMouseButtonPressed and sfvEventMouseButtonRealeased can't do it because then I have to hold a mouse at string for 3 seconds to quit app.
I need something that after 1x click start clock, play music and after 3 seconds quit app.
Please give me advice/tips whatever.
I tryed to get Input of window and then use sfMouseButtonEvent and sfButtonX1 but I don't know excatly how to use it.
Do I need place that code in Event loop or in App.IsRunning loop?
Which functions and types of events I need to use?
Really guys anything, I will keep on trying do this but help would be really needed.
-
You need a bool too store whether to mouse has been clicked or not. Then, when the sfvEventMouseButtonPressed is raised ( or buttonRelease whatever) start then clock and the music.
In each loop turn you will check if your bool is true and if the timer is correct (<3s) if not stop the music. Reset the timer and set the bool to false.
-
So in Event loop I need to check if sfButtonLeft button is pressed by using function: sfInput_IsMouseButtonDown?
And what then?
Sorry but I kind can't get it.
I will try do something with it, but still help would be needed.
EDIT: I did it with using another thread and then stoping main thread for 1 second and then clossing app but I fell like there is easier ethod to do it like that one mentioned by mooglwy but I can't get his method to work.
Could someone help me with this?
-
something like that.
[...]
bool keypressed = false;
s::clock timer;
[...]
while(true)
{
sf::Event Event;
while (App.GetEvent(Event))
{
/**/ if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space))
{
if(keypressed) break;
keypressed = true;
timer.start();
playsound();
}
}
if(keypressed && (timer > 3s)
{
exit();
}
};
With this code a music is played when you pressed space and the application quit after 3seconde. You just have to change the line with the trigger event(/**/ line). Is this clearer?
-
It's working great, thanks man.
But I am not sure if I understand all lines:
if(keypressed) break; If keypressed == TRUE quit, it's just for safe because keypressed at the beginning will always be FALSE right?
keypressed = true; Setting keypressed to TRUE
if(keypressed && (timer > 3s) Checking if keypressed == TRUE and time > 3
Is it right?
Anyway mad PROPS man, really I can't tell You grateful I am.
-
if(keypressed) break; If keypressed == TRUE quit, it's just for safe because keypressed at the beginning will always be FALSE right? it's for avoining to restart the timer and replay the music every loop.
keypressed = true; Setting keypressed to TRUE
if(keypressed && (timer > 3s) Checking if keypressed == TRUE and time > 3. yes completly right
Is it right?
Anyway mad PROPS man, really I can't tell You grateful I am.
You're wellcome. :wink:
-
If keypressed == TRUE quit, it's just for safe because keypressed at the beginning will always be FALSE right?
It's just to avoid multiple keypress ;)
-
Ahh I see, thanks guys.