예제 #1
0
        public override void Draw(Entity entity)
        {
            var sprite = entity.GetComponent <SpriteComponent>();

            if (!TryGetAnimatedSprite(sprite, out Rect2d src) && !TryGetStaticSprite(sprite, out src))
            {
                // Can't determine a valid sprite to draw
                return;
            }

            Rect2d dest = entity.Space;

            // Get the origin before any transformations are applied
            Vector2d origin = (dest.GetOriginPosition() - dest.TopLeft).ToVector();

            Rotation2d rotation = sprite.Rotation;

            if (sprite.RotationAnimation != null)
            {
                rotation.Turn(sprite.RotationAnimation.GetFrame(this.Timer.Total));
            }

            dest.Shift(sprite.Offset);
            if (sprite.OffsetAnimation != null)
            {
                dest.Shift(sprite.OffsetAnimation.GetFrame(this.Timer.Total));
            }

            dest.Scale(sprite.Scale);
            if (sprite.ScaleAnimation != null)
            {
                var animScale = sprite.ScaleAnimation.GetFrame(this.Timer.Total);
                dest.Scale(animScale);
            }

            entity.SetDirective <SpriteDirective>("simple-sprite", sd =>
            {
                sd.Asset       = sprite.SpriteSheet.Name;
                sd.Source      = src;
                sd.Destination = dest.GetOriginPosition();
                sd.Size        = dest.GetSize();
                sd.Rotation    = rotation.Radians;
                sd.Origin      = origin;
            });

            if (sprite.EnableBoxOutline)
            {
                entity.SetDirective <PolygonDirective>("simple-sprite-box-outline", pd =>
                {
                    pd.Color  = new ColorRGBA(255, 255, 0);
                    pd.Points = dest.ToPolygon().Points;
                });
            }
        }
예제 #2
0
        public void TestHashCode()
        {
            var rect1 = new Rect2d(1, 2, 3, 4);
            var rect2 = new Rect2d(1, 2, 3, 4);

            Assert.Equal(rect1.GetHashCode(), rect2.GetHashCode());

            rect2.Shift(1, 1);

            Assert.NotEqual(rect1.GetHashCode(), rect2.GetHashCode());
        }
예제 #3
0
        public void CanShiftPosition(float x1, float y1, float x2, float y2, float x3, float y3)
        {
            var width  = 30;
            var height = 40;

            var rect = new Rect2d(x1, y1, width, height, Anchor2d.BottomLeft);

            rect.Shift(x2, y2);

            DolphAssert.EqualF(x3, rect.X);
            DolphAssert.EqualF(y3, rect.Y);
            DolphAssert.EqualF(width, rect.Width);
            DolphAssert.EqualF(height, rect.Height);
        }