PlayFacing() ext

This commit is contained in:
Chris Forbes
2009-12-06 20:14:50 +13:00
parent 6594a169d8
commit 5b970c499b
5 changed files with 14 additions and 13 deletions

View File

@@ -55,7 +55,7 @@ namespace OpenRa.Game.Traits
if (currentSequence == seq) return; if (currentSequence == seq) return;
if (isFacing) if (isFacing)
anim.PlayFetchIndex(seq, () => Util.QuantizeFacing(facing, anim.CurrentSequence.Length)); anim.PlayFacing(seq, () => facing );
else else
anim.PlayRepeatingPreservingPosition(seq); anim.PlayRepeatingPreservingPosition(seq);
@@ -66,8 +66,7 @@ namespace OpenRa.Game.Traits
{ {
name = type; name = type;
anim = new Animation(type); anim = new Animation(type);
anim.PlayFetchIndex("stand", anim.PlayFacing("stand", () => facing);
() => Util.QuantizeFacing(facing, anim.CurrentSequence.Length));
location = initialLocation; location = initialLocation;
speed = ((InfantryInfo)Rules.UnitInfo[name]).Speed / 2; speed = ((InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
} }

View File

@@ -11,8 +11,7 @@ namespace OpenRa.Game.Traits
void PlayTurretAnim(Actor self, string a) void PlayTurretAnim(Actor self, string a)
{ {
anim.PlayFetchIndex(a, anim.PlayFacing(a, () => self.traits.Get<Turreted>().turretFacing);
() => self.traits.Get<Turreted>().turretFacing / 8);
} }
public override void Damaged(Actor self, DamageState ds) public override void Damaged(Actor self, DamageState ds)

View File

@@ -16,11 +16,7 @@ namespace OpenRa.Game.Traits
void PlayFacingAnim(Actor self) void PlayFacingAnim(Actor self)
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
anim.PlayFacing("idle", () => unit.Facing);
anim.PlayFetchIndex("idle",
() => Util.QuantizeFacing(
unit.Facing,
anim.CurrentSequence.Length ));
} }
public void PlayCustomAnimation(Actor self, string newAnim, Action after) public void PlayCustomAnimation(Actor self, string newAnim, Action after)

View File

@@ -20,12 +20,12 @@ namespace OpenRa.Game.Traits
var attack = self.traits.WithInterface<AttackBase>().First(); var attack = self.traits.WithInterface<AttackBase>().First();
muzzleFlash = new Animation(self.Info.Name); muzzleFlash = new Animation(self.Info.Name);
muzzleFlash.PlayFetchIndex("muzzle", muzzleFlash.PlayFetchIndex("muzzle",
() => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6 + (int)(attack.primaryRecoil * 5.9f)); () => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6
+ (int)(attack.primaryRecoil * 5.9f));
/* hack: recoil can be 1.0f, but don't overflow into next anim */ /* hack: recoil can be 1.0f, but don't overflow into next anim */
} }
turretAnim.PlayFetchIndex("turret", turretAnim.PlayFacing("turret", () => self.traits.Get<Turreted>().turretFacing);
() => self.traits.Get<Turreted>().turretFacing / 8);
} }
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self) public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)

View File

@@ -42,6 +42,13 @@ namespace OpenRa.Game.Traits
return highest * 8; return highest * 8;
} }
public static void PlayFacing(this Animation anim, string sequenceName, Func<int> facing)
{
anim.PlayFetchIndex(sequenceName,
() => Traits.Util.QuantizeFacing(facing(),
anim.CurrentSequence.Length));
}
public static int GetNearestFacing( int facing, int desiredFacing ) public static int GetNearestFacing( int facing, int desiredFacing )
{ {
var turn = desiredFacing - facing; var turn = desiredFacing - facing;