Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: simple mouse position getter not working  (Read 1086 times)

0 Members and 1 Guest are viewing this topic.

pizzatime12

  • Newbie
  • *
  • Posts: 1
    • View Profile
simple mouse position getter not working
« on: December 18, 2017, 03:31:44 am »
Quote
sf::Vector2i pixelPos = sf::Mouse::getPosition(window);
   if ( pixelPos.x > 378
      && pixelPos.x < 611
      && pixelPos.y > 385
      && pixelPos.y < 490 )
   {
      window.draw(spritePlay);
   }
   else if (pixelPos.x > 299
      && pixelPos.x < 704
      && pixelPos.y > 505
      && pixelPos.y < 623
      )
   {
      window.draw(spriteDontPlay);
   }
   else {
      window.draw(sprite);
   }

this section of code runs every frame on the main menu. "sprite" is displayed the whole time, and spriteDontPlay and spritePlay are never shown.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: simple mouse position getter not working
« Reply #1 on: December 18, 2017, 07:22:46 am »
They are only shown when your mouse is within the specified region.

And make sure this is inside your game loop.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything