Use the default sprite sequence for automatic mouse bounds.
This commit is contained in:
@@ -48,6 +48,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
{
|
{
|
||||||
public readonly Animation DefaultAnimation;
|
public readonly Animation DefaultAnimation;
|
||||||
readonly RenderSprites rs;
|
readonly RenderSprites rs;
|
||||||
|
readonly Animation boundsAnimation;
|
||||||
|
|
||||||
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
|
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
|
||||||
: this(init, info, () => 0) { }
|
: 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);
|
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
|
||||||
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
|
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)
|
if (info.StartSequence != null)
|
||||||
PlayCustomAnimation(init.Self, info.StartSequence,
|
PlayCustomAnimation(init.Self, info.StartSequence,
|
||||||
() => PlayCustomAnimationRepeating(init.Self, info.Sequence));
|
() => PlayCustomAnimationRepeating(init.Self, info.Sequence));
|
||||||
@@ -130,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
Rectangle IAutoMouseBounds.AutoMouseoverBounds(Actor self, WorldRenderer wr)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user