コード例 #1
0
 public override void DrawSprite(Sprite sprite)
 {
     sprite.SetPosition(sprite.XPosition + _camera.XOffset, sprite.YPosition + _camera.YOffset);
     if (IsOnScreen(sprite))
     {
         base.DrawSprite(sprite);
     }
 }
コード例 #2
0
        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
ファイル: Font.cs プロジェクト: WorldBeard/worldbeardsource
        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
ファイル: Batch.cs プロジェクト: WorldBeard/worldbeardsource
        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
ファイル: Camera.cs プロジェクト: WorldBeard/worldbeardsource
        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;
        }
コード例 #8
0
 public void SetTarget(Sprite targetSprite)
 {
     _targetSprite = targetSprite;
 }
コード例 #9
0
 public CharacterSprite(Sprite sprite, CharacterData data)
 {
     Sprite = sprite;
     Data = data;
 }
コード例 #10
0
 public override void Dispose()
 {
     _model = null;
 }
コード例 #11
0
 public RenderingComponent(string subclass, Sprite model)
     : base(subclass, ComponentType.Rendering)
 {
     _model = model;
 }
コード例 #12
0
 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);
 }
コード例 #15
0
 public GuiRenderingComponent(string subclass, Sprite model, string mouseOverTextureName)
     : this(subclass, model, mouseOverTextureName, "")
 {
 }
コード例 #16
0
 public GuiRenderingComponent(string subclass, Sprite model)
     : this(subclass, model, "")
 {
 }