Jump to content
  • Advertisement
Sign in to follow this  
Crusable77

sfml mouse clicking bugs

This topic is 1872 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

Hello, I am working with sfml and i am making a particle engine. The particles are supposed to follow the mouse but when I click the mouse the particles emit from the left side of the screen, Why is this and how do i fix it? I have no code to support when the button is clicked so I assumed it would do nothing.

 

this is my events loop, there is no other event handling in my program.

 

 

 
//Events
while(window.pollEvent(sfEvent)){
 
     sfMousePos.x = (float)sfEvent.mouseMove.x;
     sfMousePos.y = (float)sfEvent.mouseMove.y;
 
     switch(sfEvent.type){
 
     case sf::Event::Closed:
         window.close();
         break;
 
     case sf::Event::MouseLeft:
         bPaused = true;
         break;
 
     case sf::Event::MouseEntered:
         bPaused = false;
         break;
 
     default: break;
     }
}
Edited by Crusable

Share this post


Link to post
Share on other sites
Advertisement

It's impossible to say with that little snippet of code. That said, this looks wrong:

 

 

sfMousePos.x = (float)sfEvent.mouseMove.x;
sfMousePos.y = (float)sfEvent.mouseMove.y;
 
You don't even know if sfEvent is a MouseMoved event. First check if sfEvent.type is sf::EventMouseMoved, and if it is, then retrieve the mouse position. If it's not a MouseMoved event, then you're going to just get garbage values out of sfEvent.mouseMove.x/y (since sfEvent is a union of various events). Something like:
 

while(window.pollEvent(sfEvent)){
 
     switch(sfEvent.type){
 
     case sf::Event::Closed:
         window.close();
         break;
 
     case sf::Event::MouseMoved:
         sfMousePos.x = (float)sfEvent.mouseMove.x;
         sfMousePos.y = (float)sfEvent.mouseMove.y;
         break;
     case sf::Event::MouseLeft:
         bPaused = true;
         break;
 
     case sf::Event::MouseEntered:
         bPaused = false;
         break;
 
     default: break;
     }
}

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!