SFML community forums
Help => Window => Topic started by: magneonx on June 25, 2013, 06:52:26 pm
-
Hello I need help regarding my problem.
We know that there are 2 ways on how to listen if a mouse button was pressed:
1st you check it using poll event
2nd you can use the sf::Mouse::isButtonPressed or something like that
If you will ask, I have a sprite that fires a machine gun. So it had to be holding the button down and it fires rapidly. I also have bullet sprite stored inside vector so I can manage it easily.
One thing I have notice is that if I click the mouse button, just ONE click, it had created 70+ pointers for my bullet sprite.
I have tried the poll event. It works great!! 1 bullet per one click, but I cant hold the mouse button.
Is there anyway I could achieve my desired behavior? SHould I check for the rate of fire?
I need a gun that fires either you click the button or you hold it.
Thanks!
-
When the button is pressed, instead of adding bullets at every iteration of your logic loop, do it at a fixed/limited interval instead.
-
Wow, what an honor!
Thanks Laurent.
What have I done is combine the sf::isButtonPressed() inside the poll event loop. It achieve what I wanted. Now it fires like rail gun yeah! I havent done the fire rate logic and what I am doing, I pretty much know this is a bad idea.
The behavior of that is it only fires when I move the sprite or move the mouse, but if I stayed on one direction, it fire on intervals. I don't know how it happens. I haven't try the interval yet and mathematical concept behind it.
So I might open another topic for that one too.
-
I pretty much know this is a bad idea.
Indeed :P