Пример #1
0
 public override void DrawSprite(Sprite sprite)
 {
     sprite.SetPosition(sprite.XPosition + _camera.XOffset, sprite.YPosition + _camera.YOffset);
     if (IsOnScreen(sprite))
     {
         base.DrawSprite(sprite);
     }
 }
        public GuiRenderingComponent(string subclass, Sprite model, string mouseOverTextureName, string mouseDownTextureName)
            : base(subclass, model)
        {
            _textureDictionary.Add(GuiTextureType.NULL, model.Texture);
            if(mouseOverTextureName != "") { AddTexture(GuiTextureType.MOUSE_OVER, mouseOverTextureName); }
            if (mouseDownTextureName != "") { AddTexture(GuiTextureType.MOUSE_DOWN, mouseDownTextureName); }

            SingletonFactory.GetEventHandlerDecorator().AddHandler(this, "ChangeTexture", Events.EventType.ChangeTextureCommand, null);
        }
Пример #3
0
        public virtual void DrawSprite(Sprite sprite)
        {
            if (sprite.Texture.Id == _currentTextureID)
            {
                _batch.AddSprite(sprite);
            }
            else
            {
                _batch.Draw(); // Draw all with current texture

                // Update texture info
                _currentTextureID = sprite.Texture.Id;
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, _currentTextureID);
                _batch.AddSprite(sprite);
            }
        }
Пример #4
0
        public void RenderDebug(Sprite sprite)
        {
            Gl.glDisable(Gl.GL_TEXTURE_2D);

            RectangleF bounds = GetBoundingBox(sprite);
            Gl.glBegin(Gl.GL_LINE_LOOP);
            {
                Gl.glColor3f(1, 0, 0);
                Gl.glVertex2f(bounds.Left, bounds.Top);
                Gl.glVertex2f(bounds.Right, bounds.Top);
                Gl.glVertex2f(bounds.Right, bounds.Bottom);
                Gl.glVertex2f(bounds.Left, bounds.Bottom);
            }
            Gl.glEnd();

            Gl.glEnable(Gl.GL_TEXTURE_2D);
        }
Пример #5
0
        public CharacterSprite CreateSprite(char c)
        {
            CharacterData charData = _characterData[c];
            Sprite sprite = new Sprite();
            sprite.Texture = _texture;

            // Set up UVs
            Point topLeft = new Point((float)charData.X / (float)_texture.Width,
                (float)charData.Y / (float)_texture.Height);
            Point bottomRight = new Point((float)topLeft.X + (float) charData.Width / (float) _texture.Width,
                (float)topLeft.Y + (float) charData.Height / (float) _texture.Height);

            sprite.SetUVs(topLeft, bottomRight);
            sprite.Width = charData.Width;
            sprite.Height = charData.Height;
            sprite.Color = new Color(1, 1, 1, 1);

            return new CharacterSprite(sprite, charData);
        }
Пример #6
0
        public void AddSprite(Sprite sprite)
        {
            // If the batch is full, draw it, empty and start again
            if (sprite.VertexPositions.Length + _batchSize > MaxVertexNumber)
            {
                Draw();
            }

            // Add the current sprite vertices to the batch
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, sprite.Texture.Id);
            for (int i = 0; i < sprite.VertexPositions.Length; i++)
            {
                _vertexPositions[_batchSize + i] = sprite.VertexPositions[i];
                _vertexColors[_batchSize + i] = sprite.VertexColors[i];
                _vertexUVs[_batchSize + i] = sprite.VertexUVs[i];
            }

            _batchSize += sprite.VertexPositions.Length;
        }
Пример #7
0
        public Boolean IsOnScreen(Sprite sprite)
        {
            double leftXShifted = sprite.Left + GetXOffset();
            double rightXShifted = sprite.Right + GetXOffset();

            double topYShifted = sprite.Top + GetYOffset();
            double bottomYShifted = sprite.Bottom + GetYOffset();

            double totalXBuffer = SingletonFactory.GetFormData().HalfWidth + ConfigSettings.CAMERA_BUFFER;
            double totalYBuffer = SingletonFactory.GetFormData().HalfHeight + ConfigSettings.CAMERA_BUFFER;

            bool onScreenX = Math.Abs(leftXShifted) < totalXBuffer || Math.Abs(rightXShifted) < totalXBuffer;
            bool onScreenY = Math.Abs(topYShifted) < totalYBuffer || Math.Abs(bottomYShifted) < totalYBuffer;

            if (onScreenX && onScreenY)
            {
                return true;
            }
            return false;
        }
 public void SetTarget(Sprite targetSprite)
 {
     _targetSprite = targetSprite;
 }
 public CharacterSprite(Sprite sprite, CharacterData data)
 {
     Sprite = sprite;
     Data = data;
 }
 public override void Dispose()
 {
     _model = null;
 }
 public RenderingComponent(string subclass, Sprite model)
     : base(subclass, ComponentType.Rendering)
 {
     _model = model;
 }
 public Sprite GetSprite(String textureName, int xPos, int yPos, double width, double height)
 {
     Vector startingPosition = new Vector(xPos, yPos);
     Sprite sprite = new Sprite(this.Get(textureName), startingPosition, width, height);
     return sprite;
 }
Пример #13
0
 public bool IsOnScreen(Sprite sprite)
 {
     return _camera.IsOnScreen(sprite);
 }
Пример #14
0
 private RectangleF GetBoundingBox(Sprite sprite)
 {
     float width = (float)(sprite.Width * sprite.XScale);
     float height = (float)(sprite.Height * sprite.YScale);
     return new RectangleF((float)sprite.XPosition - width / 2,
         (float)sprite.YPosition - height / 2, width, height);
 }
 public GuiRenderingComponent(string subclass, Sprite model, string mouseOverTextureName)
     : this(subclass, model, mouseOverTextureName, "")
 {
 }
 public GuiRenderingComponent(string subclass, Sprite model)
     : this(subclass, model, "")
 {
 }