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; }); } }
public void CanScaleByMagnitude(float w1, float h1, float mag, float w2, float h2) { var x = 15; var y = 25; var rect = new Rect2d(x, y, w1, h1); rect.Scale(mag); DolphAssert.EqualF(x, rect.X); DolphAssert.EqualF(y, rect.Y); DolphAssert.EqualF(w2, rect.Width); DolphAssert.EqualF(h2, rect.Height); }
public void CanScaleByVector(float w1, float h1, float x, float y, float w2, float h2) { var rect = new Rect2d(x, y, w1, h1); rect.Scale(x, y); DolphAssert.EqualF(x, rect.X); DolphAssert.EqualF(y, rect.Y); DolphAssert.EqualF(w2, rect.Width); DolphAssert.EqualF(h2, rect.Height); rect = new Rect2d(x, y, w1, h1); rect.Scale(new Vector2d(x, y)); DolphAssert.EqualF(x, rect.X); DolphAssert.EqualF(y, rect.Y); DolphAssert.EqualF(w2, rect.Width); DolphAssert.EqualF(h2, rect.Height); }