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
コード例 #1
0
ファイル: Card.cs プロジェクト: DatZach/HumanityAgainstCards
        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);
            }
        }
コード例 #2
0
        public override void Added()
        {
            var x = _cBody.X.ToPixels();
            var y = _cBody.Y.ToPixels();

            Sprite = new Sprite(Assets.GetTexture(_textureName));
            if (_tilesetName != null && _labelName != null) Sprite.TextureRect = Assets.GetTileset(_tilesetName).GetTextureRect(_labelName);
            Sprite.Rotation = _rotation;
            Sprite.Position = new Vector2f(x, y);
            Sprite.Origin = new Vector2f(Sprite.GetGlobalBounds().Width/2, Sprite.GetGlobalBounds().Height/2);

            _game.AddDrawAction(Draw);
        }
コード例 #3
0
ファイル: CollisionManager.cs プロジェクト: Kaev/Alieanum
        public bool Collision(Sprite sprite1, Sprite sprite2, uint alphaLimit)
        {
            FloatRect intersection;
            if (sprite1.GetGlobalBounds().Intersects(sprite2.GetGlobalBounds(), out intersection))
            {
                IntRect subRect1 = sprite1.TextureRect;
                IntRect subRest2 = sprite2.TextureRect;
                uint[] mask1 = Bitmasks[sprite1.Texture];
                uint[] mask2 = Bitmasks[sprite2.Texture];

                for (int i = (int)intersection.Left; i < intersection.Left + intersection.Width; i++)
                    for (int j = (int)intersection.Top; j < intersection.Top + intersection.Height; j++)
                    {
                        Vector2f vector1 = sprite1.InverseTransform.TransformPoint(i, j);
                        Vector2f vector2 = sprite2.InverseTransform.TransformPoint(i, j);

                        if (vector1.X > 0 && vector1.Y > 0 && vector2.X > 0 && vector2.Y > 0 &&
                           vector1.X < subRect1.Width && vector1.Y < subRect1.Height &&
                           vector2.X < subRest2.Width && vector2.Y < subRest2.Height)
                            if (GetPixel(mask1, sprite1.Texture, (uint)(vector1.X) + (uint)subRect1.Left, (uint)(vector1.Y) + (uint)subRect1.Top) > alphaLimit &&
                                GetPixel(mask2, sprite2.Texture, (uint)vector2.X + (uint)subRest2.Left, (uint)vector2.Y + (uint)subRest2.Top) > alphaLimit)
                                return true;
                    }

            }

            return false;
        }
コード例 #4
0
ファイル: UnitCell.cs プロジェクト: Yozer/NanoWar
        public UnitCell(Cell targetCell, Cell sourceCell, int units, PlayerInstance player)
        {
            TargetCell = targetCell;
            SourceCell = sourceCell;
            Units = UnitsLeft = units;
            _currentVelocity = Velocity;

            string colorName = null;
            if (SourceCell.Player.Color.R == 255 && SourceCell.Player.Color.G == 0 && SourceCell.Player.Color.B == 0)
            {
                colorName = "red";
            }
            else if (SourceCell.Player.Color.R == 0 && SourceCell.Player.Color.G == 255 && SourceCell.Player.Color.B == 0)
            {
                colorName = "green";
            }
            else if (SourceCell.Player.Color.R == 0 && SourceCell.Player.Color.G == 0
                     && SourceCell.Player.Color.B == 255)
            {
                colorName = "blue";
            }

            _sprite = new Sprite(ResourceManager.Instance["game/unit_cell_" + colorName] as Texture);

            _text = new Text(units.ToString(), ResourceManager.Instance["fonts/verdana"] as Font, FontSize);
            _text.Origin = new Vector2f(
                _text.GetLocalBounds().Left + _text.GetLocalBounds().Width / 2,
                _text.GetLocalBounds().Top);

            _particleSystem = new ParticleSystem(ResourceManager.Instance["game/particle"] as Texture);

            var scale = 0.5f + Units * 0.0125f;
            if (scale >= 1f)
            {
                scale = 1f;
            }

            Scale = _initialScale = new Vector2f(scale, scale);

            Radius = _sprite.GetGlobalBounds().Height / 2;
            _sprite.Origin = new Vector2f(_sprite.GetLocalBounds().Width / 2, _sprite.GetLocalBounds().Height / 2);
            SourcePlayer = player;
        }