Sequence.facing idea/RFC.

This commit is contained in:
Bob
2010-02-11 12:20:06 +13:00
parent f1db8c6f07
commit 62198067d6
5 changed files with 33 additions and 21 deletions

View File

@@ -10,12 +10,20 @@ namespace OpenRa.Graphics
bool backwards = false;
bool tickAlways;
Func<int> facingFunc;
public string Name { get { return name; } }
public Animation( string name )
: this( name, () => 0 )
{
}
public Animation( string name, Func<int> facingFunc )
{
this.name = name.ToLowerInvariant();
tickFunc = () => { };
this.tickFunc = () => { };
this.facingFunc = facingFunc;
}
public Sprite Image
@@ -23,8 +31,8 @@ namespace OpenRa.Graphics
get
{
return backwards
? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1)
: CurrentSequence.GetSprite(frame);
? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1, facingFunc())
: CurrentSequence.GetSprite(frame, facingFunc());
}
}

View File

@@ -5,12 +5,13 @@ namespace OpenRa.Graphics
public class Sequence
{
readonly Sprite[] sprites;
readonly int start, length;
readonly int start, length, facings;
public readonly string Name;
public int Start { get { return start; } }
public int End { get { return start + length; } }
public int Length { get { return length; } }
public int Facings { get { return facings; } }
public Sequence(string unit, XmlElement e)
{
@@ -28,11 +29,22 @@ namespace OpenRa.Graphics
length = int.Parse(e.GetAttribute("end")) - int.Parse(e.GetAttribute("start"));
else
length = 1;
if( e.HasAttribute( "facings" ) )
facings = int.Parse( e.GetAttribute( "facings" ) );
else
facings = 1;
}
public Sprite GetSprite(int frame)
public Sprite GetSprite( int frame )
{
return sprites[ ( frame % length ) + start ];
return GetSprite( frame, 0 );
}
public Sprite GetSprite(int frame, int facing)
{
var f = Traits.Util.QuantizeFacing( facing, facings );
return sprites[ (f * length) + ( frame % length ) + start ];
}
}
}