예제 #1
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Validate();

            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);

            float x      = X;
            float y      = Y;
            float scaleX = ScaleX;
            float scaleY = ScaleY;

            if (_drawable != null)
            {
                if (_drawable is TextureRegionDrawable)
                {
                    TextureRegion region   = (Drawable as TextureRegionDrawable).Region;
                    float         rotation = Rotation;
                    if (scaleX == 1 && scaleY == 1 && rotation == 0)
                    {
                        spriteBatch.Draw(region, x + ImageX, y + ImageY, ImageWidth, ImageHeight);
                    }
                    else
                    {
                        spriteBatch.Draw(region, x + ImageX, y + ImageY, OriginX - ImageX, OriginY - ImageY, ImageWidth, ImageHeight, scaleX, scaleY, rotation);
                    }
                }
                else
                {
                    _drawable.Draw(spriteBatch, x + ImageX, y + ImageY, ImageWidth * scaleX, ImageHeight * scaleY);
                }
            }
        }
예제 #2
0
 public override void Draw(GdxSpriteBatch spriteBatch, float x, float y, float width, float height)
 {
     spriteBatch.Draw(Region, x, y, width, height);
 }
예제 #3
0
        public override void Draw(GdxSpriteBatch spriteBatch, float x, float y, float width, float height)
        {
            TextureRegion region = Region;

            float regionWidth  = region.RegionWidth;
            float regionHeight = region.RegionHeight;
            float remainingX   = width % regionWidth;
            float remainingY   = height % regionHeight;

            float startX = x;
            float startY = y;
            float endX   = x + width - remainingX;
            float endY   = y + height - remainingY;

            while (x < endX)
            {
                y = startY;
                while (y < endY)
                {
                    spriteBatch.Draw(region, x, y, regionWidth, regionHeight);
                    y += regionHeight;
                }
                x += regionWidth;
            }

            TextureContext texture = region.Texture;
            float          u       = region.U;
            float          v2      = region.V2;

            if (remainingX > 0)
            {
                float u2 = u + remainingX / texture.Width;
                float v  = region.V;

                y = startY;
                while (y < endY)
                {
                    spriteBatch.Draw(texture, x, y, remainingX, regionHeight, u, v2, u2, v);
                    y += regionHeight;
                }

                if (remainingY > 0)
                {
                    v = v2 - remainingY / texture.Height;
                    spriteBatch.Draw(texture, x, y, remainingX, remainingY, u, v2, u2, v);
                }
            }

            if (remainingY > 0)
            {
                float u2 = region.U2;
                float v  = v2 - remainingY / texture.Height;

                x = startX;
                while (x < endX)
                {
                    spriteBatch.Draw(texture, x, y, regionWidth, remainingY, u, v2, u2, v);
                    x += regionWidth;
                }
            }
        }