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 CanGetPositionAtOrigin() { var anchor = Anchor2d.MiddleRight; var rect = new Rect2d(100, 200, 300, 400, anchor); var pos1 = rect.GetAnchorPosition(anchor); var pos2 = rect.GetOriginPosition(); Assert.Equal(pos1, pos2); }