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

View File

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

View File

@@ -16,11 +16,7 @@ namespace OpenRa.Game.Traits
void PlayFacingAnim(Actor self)
{
var unit = self.traits.Get<Unit>();
anim.PlayFetchIndex("idle",
() => Util.QuantizeFacing(
unit.Facing,
anim.CurrentSequence.Length ));
anim.PlayFacing("idle", () => unit.Facing);
}
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();
muzzleFlash = new Animation(self.Info.Name);
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 */
}
turretAnim.PlayFetchIndex("turret",
() => self.traits.Get<Turreted>().turretFacing / 8);
turretAnim.PlayFacing("turret", () => self.traits.Get<Turreted>().turretFacing);
}
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)

View File

@@ -42,6 +42,13 @@ namespace OpenRa.Game.Traits
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 )
{
var turn = desiredFacing - facing;