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

Author Topic: Sprite click trigger  (Read 1811 times)

0 Members and 1 Guest are viewing this topic.

megamen128

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite click trigger
« on: December 16, 2016, 07:37:19 pm »
Hi
Im beginner in SFML and i have one problem.
I wrote my own OnSpriteClick method witch works great untill i used it in if statement .
the second IsSpiritClicked (Pauza.IsSpiteClicked) trigger whenever i cover spirit with mouse.

if (Start.IsSpiteClicked(Window, Start.Sprite, Event))
         {
         bool end = false;
            while (end != true)
            {
               if (Pauza.IsSpiteClicked(Window, Pauza.Sprite, Event))
                  end = true;
                                     /* OTHER CODE */
                                }
                           }


And this is the method

bool Buttom::IsSpiteClicked(sf::RenderWindow &x, sf::Sprite &y , sf::Event &event)
{
   sf::Vector2f mouse(sf::Mouse::getPosition(x));
   if (event.type == sf::Event::MouseButtonPressed && event.key.code == sf::Mouse::Left && y.getGlobalBounds().contains(mouse))
      return true;
   else return false;
}

event is a sf::Event
Window is a sf::RenderWindow
Start is my own class Button

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11004
    • View Profile
    • development blog
    • Email
Sprite click trigger
« Reply #1 on: December 16, 2016, 08:08:20 pm »
If there is a problem with the code, you need to tell us what it is. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

megamen128

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprite click trigger
« Reply #2 on: December 16, 2016, 08:33:32 pm »
Like i said Pauza button triggers whenever i cover the button spirit with mouse . It should trigger when i click on it. While loop end when i cover pauze button
« Last Edit: December 16, 2016, 08:35:22 pm by megamen128 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11004
    • View Profile
    • development blog
    • Email
Sprite click trigger
« Reply #3 on: December 16, 2016, 08:45:01 pm »
Well the code is not complete, as such it's not really possible to tell where the issue is. You shouldn't use an infinite loop, since that will block event processing as well as rendering. Instead you can use additional variables to saw the states.

Make sure to read the event/real time input tutorial, you shouldn't be mixing those two.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

megamen128

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprite click trigger
« Reply #4 on: December 16, 2016, 08:56:38 pm »
Its game of life simulation so i think it has to be infinite loop . But i also want be able to pause or speed up or down while the simulation in going

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11004
    • View Profile
    • development blog
    • Email
Sprite click trigger
« Reply #5 on: December 16, 2016, 08:58:10 pm »
Just look at the examples in the SFML tutorials to see what a proper game loop should look like.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/