GetLocalBounds() public method

Get the local bounding rectangle of the entity. The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.
public GetLocalBounds ( ) : FloatRect
return FloatRect
Example #1
1
 //constructor
 //Possibly requires explicit keyword
 public Aircraft(Type type, ResourceHolder<Texture, ResourceID> textures)
 {
     mType = type;
     mSprite = new Sprite(textures.get(toTextureID(type)));
     FloatRect bounds = mSprite.GetLocalBounds();
     mSprite.Origin = new Vector2f(bounds.Width / 2, bounds.Height / 2);
 }
Example #2
0
        /// <summary>
        /// Creates a Sprite from RenderImage Texture and draws it to the screen
        /// </summary>
        /// <param name="Position"> Position of Texture </param>
        /// <param name="Size"> Size of the Texture </param>
        /// <param name="color"> Global color of object </param>
        public void Blit(SFML.System.Vector2f position, SFML.System.Vector2f Size, SFML.Graphics.Color color)
        {
            isStillDrawing();
            blitsprite          = new SFML.Graphics.Sprite(Texture);
            blitsprite.Position = position;
            blitsprite.Color    = color;
            var bounds = blitsprite.GetLocalBounds();

            if (Mode == BlitterSizeMode.Scale)
            {
                SFML.System.Vector2f scale = new SFML.System.Vector2f((Size.X / bounds.Width), (Size.Y / bounds.Height));
                blitsprite.Scale = scale;
            }
            else if (Mode == BlitterSizeMode.Crop)
            {
                IntRect crop = new IntRect((int)position.X, (int)position.Y, (int)Size.X, (int)Size.Y);
                blitsprite.TextureRect = crop;
            }


            if (CluwneLib.CurrentRenderTarget == this)
            {
                return;
            }

            blitsprite.Draw();
        }
Example #3
0
        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;
        }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="resManager">Gestor de recursos</param>
        /// <param name="worldBounds">Dimensiones de area de movimiento del PlayerShip</param>
        /// <param name="shootPool">Piscina que gestiona el reciclaje de las balas</param>
        public PlayerShip(ResourcesManager resManager, FloatRect worldBounds,ShootPlayerPool shootPool)
            : base() 
        {
            _sprite = new Sprite((Texture)resManager["Naves:NaveJugador"]);
            _worldBounds = worldBounds;

            // ubico el origen del sprite en el centro en vez de en la esquina superior derecha
            FloatRect bounds = _sprite.GetLocalBounds();
            _sprite.Origin = new SFML.System.Vector2f(bounds.Width / 2f, bounds.Height / 2f);

            _shootPool = shootPool;
        }
Example #5
0
        public Button(ResourceHolder<Font, FontID> fonts, ResourceHolder<Texture, ResourceID> textures) 
        {
            //ACTION IS NOT INITIALIZED
            mNormalTexture = new Texture(textures.get(ResourceID.ButtonNormal));
            mSelectedTexture = new Texture(textures.get(ResourceID.ButtonSelected));
            mPressedTexture = new Texture(textures.get(ResourceID.ButtonPressed));

            mSprite = new Sprite(mNormalTexture);

            mText = new Text("", fonts.get(FontID.Main), 16);
            mIsToggle = false;

            FloatRect bounds = mSprite.GetLocalBounds();
            mText.Position = new Vector2f(bounds.Width / 2, bounds.Height / 2);
        }
Example #6
0
        public ServerSelector()
        {
            _shape.FillColor = Color.Transparent;
            _shape.OutlineThickness = 3.0f;
            _shape.OutlineColor = Color.White;
            _shape.Size = new Vector2f(350, 300);
            _shape.Origin = new Vector2f(_shape.Size.X / 2, _shape.Size.Y / 2);
            _shape.Position = new Vector2f(Game.Instance.Width / 2, Game.Instance.Height / 2 + _shape.Size.Y);

            SelectedLobbyId = -1;

            _arrow = new Sprite(ResourceManager.Instance["multiplayer/arrow"] as Texture);
            _arrow.Origin = new Vector2f(0, _arrow.GetLocalBounds().Height / 2);
            _arrow.Position = new Vector2f(_shape.Position.X - _shape.GetLocalBounds().Width / 2 + 10, 0);
        }
Example #7
0
        public static bool SpritePixelHit(Sprite toCheck, Vector2f clickPos)
        {
            var clickPoint = new Vector2f(clickPos.X, clickPos.Y);
            if (!toCheck.GetLocalBounds().Contains(clickPoint.X, clickPoint.Y)) return false;

            var spritePosition = new Vector2u((uint) clickPos.X - (uint) toCheck.Position.X ,//+ (int) toCheck.ImageOffset.X,
                                           (uint) clickPos.Y - (uint) toCheck.Position.Y ); //+ (int) toCheck.ImageOffset.Y);

            Image imgData = toCheck.Texture.CopyToImage();

            //imgData.Lock(false);
            Color pixColour = imgData.GetPixel(spritePosition.X, spritePosition.Y);
            imgData.Dispose();
            //imgData.Unlock();

            return pixColour.A != 0;
        }
        public ExamineWindow(Vector2i size, Entity entity, IResourceManager resourceManager)
            : base(entity.Name, size, resourceManager)
        {
            _resourceManager = resourceManager;
            _entityDescription = new Label(entity.GetDescriptionString(), "CALIBRI", _resourceManager);

            components.Add(_entityDescription);

            ComponentReplyMessage reply = entity.SendMessage(entity, ComponentFamily.Renderable,
                                                             ComponentMessageType.GetSprite);

            SetVisible(true);

            if (reply.MessageType == ComponentMessageType.CurrentSprite)
            {
                _entitySprite = (Sprite) reply.ParamsList[0];
                _entityDescription.Position = new Vector2i(10,
                                                        (int)_entitySprite.GetLocalBounds().Height +
                                                        _entityDescription.ClientArea.Height + 10);
            }
            else
                _entityDescription.Position = new Vector2i(10, 10);
        }
Example #9
0
        public Aircraft(Type type, ResourceHolder<Texture, ResourceID> textures, ResourceHolder<Font,FontID> fonts) :base(Table[(int)type].hitpoints)
        { 
            mType = type; 
            mSprite = new Sprite(textures.get(toTextureID(type)));
            FloatRect bounds = mSprite.GetLocalBounds();
            mSprite.Origin = new Vector2f(bounds.Width / 2, bounds.Height / 2);

            TextNode healthDisplay = new TextNode(fonts, " "); ;
            mHealthDisplay = healthDisplay;
            attachChild(healthDisplay);

            mTravelledDistance = 0;
            mDirectionIndex = 0;

            mIsFiring = false;
            mIsLaunchingMissile = false;
            MissileAmmo = 3;
            mIsMarkedForRemoval = false;
            mFireCountdown = Time.Zero;
            mFireRateLevel = 1;
            mSpreadLevel = 1;

            mFireCommand = new Command();
            mFireCommand.category = (uint)Category.PlayerAircraft;
            mFireCommand.actionfunc = (SceneNode node, Time time) =>
            {
                SceneNode aircraft = (Aircraft)node;
                createBullets(aircraft, textures);
            };

            mLaunchCommand = new Command();
        }
Example #10
0
        /// <summary>
        /// Creates a Sprite from RenderImage Texture and draws it to the screen
        /// </summary>
        /// <param name="Position"> Position of Texture </param>
        /// <param name="Size"> Size of the Texture </param>
        /// <param name="color"> Global color of object </param>
        public void Blit(SFML.System.Vector2f position, SFML.System.Vector2f Size, SFML.Graphics.Color color)
        {
            isStillDrawing();
            blitsprite = new SFML.Graphics.Sprite(Texture);
            blitsprite.Position = position;
            blitsprite.Color = color;
            var bounds = blitsprite.GetLocalBounds();

            if (Mode == BlitterSizeMode.Scale)
            {
                SFML.System.Vector2f scale = new SFML.System.Vector2f(( Size.X / bounds.Width ),( Size.Y / bounds.Height ));
                blitsprite.Scale = scale;

            }
            else if (Mode == BlitterSizeMode.Crop)
            {
                IntRect crop = new IntRect((int)position.X, (int)position.Y, (int)Size.X, (int)Size.Y);
                blitsprite.TextureRect = crop;

            }

            if (CluwneLib.CurrentRenderTarget == this)
                return;

            blitsprite.Draw();
        }
Example #11
0
        public void Draw(Vector2f position, Vector2f windowOrigin, Sprite spriteToDrawAbove)
        {
            if ((DateTime.Now - _buildTime).TotalMilliseconds >= MillisecondsToLive) return;

            var bubbleBounds = _bubbleSprite.GetLocalBounds();
            var spriteBounds = spriteToDrawAbove.GetLocalBounds();

            float x = position.X - windowOrigin.X - (bubbleBounds.Width / 2.0f);
            float y = position.Y - windowOrigin.Y - (bubbleBounds.Height) - (spriteBounds.Height / 2.0f) - 5.0f;

            _bubbleSprite.Position = new Vector2f(x, y);
            _bubbleSprite.Draw();
        }
Example #12
0
        public Shoot(Type type)
            : base()
        {
            _type = type;

            _sprite = new Sprite((Texture)ShootTypeConf[(int)_type]._resManager[ShootTypeConf[(int)_type]._textureKey]);
            _sprite.Scale = new Vector2f(0.7f, 0.7f);
            // ubico el origen del sprite en el centro en vez de en la esquina superior izquierda
            FloatRect bounds = _sprite.GetLocalBounds();
            _sprite.Origin = new SFML.System.Vector2f(bounds.Width / 2f, bounds.Height / 2f);

            VelocityY = ShootTypeConf[(int)_type]._maxSpeed;

            _collider = new ColliderRect(bounds, new SFML.System.Vector2f(bounds.Width / 2f, bounds.Height / 2f));
        }