Fixed #2696: Sequences: Allow stride to be specified.
This allows you to use just some of the frames of an animation
which has multiple facings.
For example, if you have an animation which has 8 facings, and 6 frames
of animation per facing, but you only want to show 3 of them, you can now do:
Facings: 8
Length: 3 # the number of frames in each facing to actually use
Stride: 6 # the number of frames per facing present in the SHP
If Stride is not specified, it defaults to Length, which is the old behavior.
It is an error to specify a stride less than the length -- this would produce
overlapping facings, or weirder.
This commit is contained in:
@@ -18,12 +18,13 @@ namespace OpenRA.Graphics
|
||||
public class Sequence
|
||||
{
|
||||
readonly Sprite[] sprites;
|
||||
readonly int start, length, facings, tick;
|
||||
readonly int start, length, stride, facings, tick;
|
||||
|
||||
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 Stride { get { return stride; } }
|
||||
public int Facings { get { return facings; } }
|
||||
public int Tick { get { return tick; } }
|
||||
|
||||
@@ -43,6 +44,10 @@ namespace OpenRA.Graphics
|
||||
else
|
||||
length = int.Parse(d["Length"].Value);
|
||||
|
||||
if (d.ContainsKey("Stride"))
|
||||
stride = int.Parse(d["Stride"].Value);
|
||||
else
|
||||
stride = length;
|
||||
|
||||
if(d.ContainsKey("Facings"))
|
||||
facings = int.Parse(d["Facings"].Value);
|
||||
@@ -54,10 +59,15 @@ namespace OpenRA.Graphics
|
||||
else
|
||||
tick = 40;
|
||||
|
||||
if (start < 0 || start + facings * length > sprites.Length)
|
||||
if (length > stride)
|
||||
throw new InvalidOperationException(
|
||||
"{0}: Sequence {1}.{2}: Length must be <= stride"
|
||||
.F(info.Nodes[0].Location, unit, name));
|
||||
|
||||
if (start < 0 || start + facings * stride > sprites.Length)
|
||||
throw new InvalidOperationException(
|
||||
"{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist"
|
||||
.F(unit, name, start, start + facings * length - 1, srcOverride ?? unit, sprites.Length - 1,
|
||||
.F(unit, name, start, start + facings * stride - 1, srcOverride ?? unit, sprites.Length - 1,
|
||||
info.Nodes[0].Location));
|
||||
}
|
||||
|
||||
@@ -69,7 +79,7 @@ namespace OpenRA.Graphics
|
||||
public Sprite GetSprite(int frame, int facing)
|
||||
{
|
||||
var f = Traits.Util.QuantizeFacing( facing, facings );
|
||||
return sprites[ (f * length) + ( frame % length ) + start ];
|
||||
return sprites[ (f * stride) + ( frame % length ) + start ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user