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

Author Topic: Sprite bounds problem?  (Read 1655 times)

0 Members and 1 Guest are viewing this topic.

ILostMyAccount

  • Newbie
  • *
  • Posts: 22
    • View Profile
Sprite bounds problem?
« on: February 20, 2015, 01:04:18 pm »
I'm trying to make a button, everything is working fine, except for one thing.
If I try to move or scale the button the bounds don't change, and obviously the mouseclick still gets detected at the initial position.

This is my button update code:
                mCDTime = mCDClock.getElapsedTime();
                if (mEnabled && mCDTime > sf::Time(sf::seconds(0.30f)))
                {
                        auto spriteBounds = mSprite.getLocalBounds();
                        auto mousePosition = sf::Mouse::getPosition(*mWindowPtr);
                        if (spriteBounds.contains(static_cast<sf::Vector2f>(mousePosition)) && sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                        {
                                OnClick();
                                mCDClock.restart();
                        }
                        mText.setPosition(mSprite.getPosition());
                        mText.setScale(mSprite.getScale());
                        mText.setRotation(mSprite.getRotation());
                }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite bounds problem?
« Reply #1 on: February 20, 2015, 01:23:20 pm »
Test against the global bounds, not the local ones.
Laurent Gomila - SFML developer

ILostMyAccount

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Sprite bounds problem?
« Reply #2 on: February 20, 2015, 02:05:41 pm »
Test against the global bounds, not the local ones.
Thank you, that fixed the problem