Use the default sprite sequence for automatic mouse bounds.

This commit is contained in:
Paul Chote
2018-06-22 18:33:38 +01:00
committed by reaperrr
parent 707514572b
commit 6b6167d37c

View File

@@ -48,6 +48,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{
public readonly Animation DefaultAnimation;
readonly RenderSprites rs;
readonly Animation boundsAnimation;
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
: this(init, info, () => 0) { }
@@ -63,6 +64,10 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
// Cache the bounds from the default sequence to avoid flickering when the animation changes
boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
boundsAnimation.PlayRepeating(info.Sequence);
if (info.StartSequence != null)
PlayCustomAnimation(init.Self, info.StartSequence,
() => PlayCustomAnimationRepeating(init.Self, info.Sequence));
@@ -130,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits.Render
Rectangle IAutoMouseBounds.AutoMouseoverBounds(Actor self, WorldRenderer wr)
{
return DefaultAnimation != null ? DefaultAnimation.ScreenBounds(wr, self.CenterPosition, WVec.Zero, rs.Info.Scale) : Rectangle.Empty;
return boundsAnimation.ScreenBounds(wr, self.CenterPosition, WVec.Zero, rs.Info.Scale);
}
}
}