Skip to content

Commit

Permalink
Improve sequence rendering accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed Jun 2, 2020
1 parent 17da8a7 commit 79a4998
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions OpenKh.Engine/Renders/ISpriteDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

namespace OpenKh.Engine.Renders
{
public enum BlendMode
{
Default,
Add,
Subtract,
}

public struct ColorF
{
public static readonly ColorF Black = new ColorF(0.0f, 0.0f, 0.0f, 1.0f);
Expand Down Expand Up @@ -77,6 +84,7 @@ public class SpriteDrawingContext
public ColorF Color3 { get; set; }

public ISpriteTexture SpriteTexture { get; set; }
public BlendMode BlendMode { get; set; }
}

public static class SpriteDrawingContextExtensions
Expand Down
7 changes: 4 additions & 3 deletions OpenKh.Engine/Renders/SequenceRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private class Context
public float ScaleX { get; set; }
public float ScaleY { get; set; }
public ColorF Color { get; set; }
public int ColorBlendType { get; set; }
public int ColorBlendMode { get; set; }
public float Left { get; set; }
public float Top { get; set; }
public float Right { get; set; }
Expand All @@ -28,7 +28,7 @@ private class Context
ScaleX = ScaleX,
ScaleY = ScaleY,
Color = Color,
ColorBlendType = ColorBlendType,
ColorBlendMode = ColorBlendMode,
Left = Left,
Top = Top,
Right = Right,
Expand Down Expand Up @@ -112,7 +112,7 @@ private void DrawAnimation(Context contextParent, Sequence.Animation animation)

context.PositionX += Lerp(t, animation.Xa0, animation.Xa1);
context.PositionY += Lerp(t, animation.Ya0, animation.Ya1);
context.ColorBlendType = animation.ColorBlend;
context.ColorBlendMode = animation.ColorBlend;

if ((animation.Flags & ScalingFlag) == 0)
{
Expand Down Expand Up @@ -188,6 +188,7 @@ private void DrawFrame(Context context, Sequence.Frame frame)
drawContext.Color2 = ConvertColor(frame.ColorRight);
drawContext.Color3 = ConvertColor(frame.ColorBottom);
drawContext.ColorMultiply(context.Color);
drawContext.BlendMode = (BlendMode)context.ColorBlendMode;

drawing.AppendSprite(drawContext);
}
Expand Down

0 comments on commit 79a4998

Please sign in to comment.