SFML.Graphics.Sprite.GetGlobalBounds C# (CSharp) Method

GetGlobalBounds() public method

Get the global bounding rectangle of the entity. The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the sprite in the global 2D world's coordinate system.
public GetGlobalBounds ( ) : FloatRect
return FloatRect
        public FloatRect GetGlobalBounds()
        {
            // we don't use the native getGlobalBounds function,
            // because we override the object's transform
            return Transform.TransformRect(GetLocalBounds());
        }

Usage Example

Example #1
0
        public override void Draw(RenderTarget rt)
        {
            Vector2f actualPosition = Position + (Selected ? new Vector2f(0, -12.0f - 5.0f * GetSelectedIndex()) : new Vector2f());

            // Draw card
            Sprite sprite = new Sprite(Assets.LoadTexture(Info.Type == CardType.White ? "CardWhite.png" : "CardBlack.png"));
            Size = new Vector2f(sprite.GetGlobalBounds().Width, sprite.GetGlobalBounds().Height);
            sprite.Position = actualPosition;
            sprite.Scale = Scale;
            rt.Draw(sprite);

            // Draw text
            Text text = GameUtility.Wrap(Info.Value, Assets.LoadFont("arialbd.ttf"), (uint)Math.Floor(24.0f * Scale.X),
                                     Math.Floor(207.0f * Scale.X));

            text.Color = Info.Type == CardType.White ? Color.Black : Color.White;
            text.Position = actualPosition + new Vector2f(16.0f * Scale.X, 10.0f * Scale.Y);
            text.Round();
            rt.Draw(text);

            // Draw decorations
            if (Info.PickCount > 1)
            {
                Sprite pickMultiple = new Sprite(Assets.LoadTexture(Info.PickCount == 2 ? "PickTwo.png" : "PickThree.png"))
                {
                    Position =
                        actualPosition +
                        new Vector2f((241.0f - 56.0f - 10.0f - 4.0f) * Scale.X, (320.0f - 10.0f - 20.0f) * Scale.Y),
                    Scale = Scale
                };

                rt.Draw(pickMultiple);
            }
        }
All Usage Examples Of SFML.Graphics.Sprite::GetGlobalBounds