Skip to content

Commit cba13dc

Browse files
Add Sprite.IndependentRotation to allow the sprite to not follow its parent's rotation
1 parent 88b53bb commit cba13dc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Wobble/Graphics/Sprites/Sprite.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ public float Alpha {
8686
}
8787
}
8888

89+
private bool _independentRotation;
90+
91+
/// <summary>
92+
/// If true, the rotation of sprite shown on screen will be independent of its parent.
93+
/// </summary>
94+
public bool IndependentRotation
95+
{
96+
get => _independentRotation;
97+
set
98+
{
99+
_independentRotation = value;
100+
SpriteRotation = value ? Rotation : AbsoluteRotation;
101+
}
102+
}
103+
104+
/// <summary>
105+
/// Actual rotation of sprite shown on screen.
106+
/// It is decided by <see cref="IndependentRotation"/> and parent's <see cref="Drawable.AbsoluteRotation"/>
107+
/// </summary>
108+
public float SpriteRotation { get; private set; }
109+
89110
/// <summary>
90111
/// Dictates if we want to set the alpha of the children as well.
91112
/// </summary>
@@ -152,7 +173,7 @@ public override void DrawToSpriteBatch()
152173
if (!Visible)
153174
return;
154175

155-
GameBase.Game.SpriteBatch.Draw(Image, RenderRectangle, null, _color, AbsoluteRotation, Origin, SpriteEffect, 0f);
176+
GameBase.Game.SpriteBatch.Draw(Image, RenderRectangle, null, _color, SpriteRotation, Origin, SpriteEffect, 0f);
156177
}
157178

158179
/// <inheritdoc />
@@ -180,6 +201,8 @@ protected override void OnRectangleRecalculated()
180201
// Update the render rectangle
181202
RenderRectangle = new RectangleF(ScreenRectangle.X + rotatedScreenOrigin.X, ScreenRectangle.Y + rotatedScreenOrigin.Y,
182203
ScreenRectangle.Width, ScreenRectangle.Height);
204+
205+
SpriteRotation = IndependentRotation ? Rotation : AbsoluteRotation;
183206
}
184207

185208
/// <summary>

0 commit comments

Comments
 (0)