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

Author Topic: Sprite.Location does not update Sprite.TextureRect  (Read 3707 times)

0 Members and 1 Guest are viewing this topic.

booooo201

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sprite.Location does not update Sprite.TextureRect
« on: June 01, 2014, 08:41:11 pm »
I don't really know if this is just me being stupid(Which it probably is..), but I have two buttons, and I set the location of them with the location property. Now I'm trying to see if the button has been pressed using an IntRect, but its in the top left corner(after some rigorous debugging), indicating that the property wasn't updated.

This is the part where I try to see if the button is pressed..

        public void Update(RenderWindow window)
        {
            if (Mouse.IsButtonPressed(Mouse.Button.Left))
            {
                //Program.WriteDebug("Mouse was clicked.");
                Vector2i mousePosition = Mouse.GetPosition(window);
                if (play.TextureRect.Contains(mousePosition.X, mousePosition.Y))
                {
                     // Is not displayed.
                    Program.WriteDebug("Play button pressed.");
                }
                else if (quit.TextureRect.Contains(mousePosition.X, mousePosition.Y))
                {
                    // Not displayed either.. Woo.
                    Program.WriteDebug("Quit button pressed");
                }
            }
        }

And the whole class if you're wondering.
(click to show/hide)

Also, the entire application is set as a console application to see the console.
One more thing, when I try to manually set the IntRect, the button just disappears. Sigh.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sprite.Location does not update Sprite.TextureRect
« Reply #1 on: June 01, 2014, 10:05:27 pm »
Why would you think the Sprite.Position has anything to do with the TextureRect?

http://www.sfml-dev.org/documentation/2.1/classsf_1_1Sprite.php#a3fefec419a4e6a90c0fd54c793d82ec2

Quote
Set the sub-rectangle of the texture that the sprite will display.

The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

booooo201

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Sprite.Location does not update Sprite.TextureRect
« Reply #2 on: June 01, 2014, 11:21:55 pm »
Why would you think the Sprite.Position has anything to do with the TextureRect?

http://www.sfml-dev.org/documentation/2.1/classsf_1_1Sprite.php#a3fefec419a4e6a90c0fd54c793d82ec2

Quote
Set the sub-rectangle of the texture that the sprite will display.

The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.

Thanks, I didn't read the docs. I make a new rectangle variable and calculated it from that.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite.Location does not update Sprite.TextureRect
« Reply #3 on: June 02, 2014, 07:47:03 am »
Quote
I didn't read the docs
Next time please do, before posting on the forum ;)
Laurent Gomila - SFML developer