I'll post my understanding of the code, but first here is the issue I am having:
Code: Select all
Anims[i].Animated.Texture = Anims[i].Animation.GetByPosition(1); // Error, Type mismatch in '='If you're with me beyond that, here are the three actors:
Code: Select all
class SpriteAnimation expands Object;
struct AnimNotify
{
var name CallOnFrame;
var int PlayOnFrame;
};
var float DefaultAnimTime;
var array AnimFrames;
var array AnimNotifies; // Accesses the data DIRECTLY FROM AnimNotify
final function BitMap GetByPosition( float InPos)
{
local int aSize;
aSize = Array_Size( AnimFrames);
return AnimFrames[ int(InPos*float(aSize)) % aSize ];
}Code: Select all
//=============================================================================
// SpriteAnimationManager.
// In charge of updating the animations independantly, pooled into an animation manager.
//=============================================================================
class SpriteAnimationManager expands Actor;
struct AnimRegister
{
var Actor Animated;
var SpriteAnimation Animation;
var float AnimRate;
var float CurPosition;
var int RepeatCount;
var bool bLooping;
var bool bNotify;
var name FinishNotify;
}; // Establish an AnimRegister
var private array Anims;
event Tick( float DeltaTime)
{
local int i, Max;
local float OldPosition;
local bool bRemove;
Max = Array_Size( Anims);
for ( i=0 ; i= 1) ) // Animation has completed a cycle
{
if ( !Anims[i].bLooping && (Anims[i].RepeatCount-- = 0 )
Array_Remove( Anims, Idx, 1);
return Idx >= 0;
}
function ChangeRate( Actor sAnimated);
function SetNotifyState( Actor sAnimated, bool bEnable, optional name NewOptNotify);
//RepeatCount = -1 means loop (default = 0, one shot)
// Rate is (1/Time) anim takes to complete, feel free to call the function like that
// EndNotify = '' (or unspecified) means no callback
function PlayAnimation( Actor sAnimated, SpriteAnimation sAnimation, float Rate, optional int RepeatCount, optional name EndNotify )
{
local int Num;
Num = GetByActor( sAnimated);
if ( Num == -1 )
{
Num = Array_Size( Anims);
if ( !Array_Insert( Anims, Num, 1) )
{
Log("ERROR: Failed to allocate animation register for "$sAnimated.Name);
return;
}
}
Anims[Num].Animated = sAnimated;
Anims[Num].Animation = sAnimation;
Anims[Num].AnimRate = Rate;
Anims[Num].CurPosition = 0;
Anims[Num].bLooping = (RepeatCount == -1);
Anims[Num].RepeatCount = RepeatCount;
Anims[Num].bNotify = (EndNotify != '');
Anims[Num].FinishNotify = EndNotify;
sAnimated.Texture = sAnimation.GetByPosition(0); // Error, Type mismatch in '='
}
// return -1 means no index, no animation for this actor
// Good way to see if an actor is being animated by THIS manager
final function int GetByActor( Actor sAnimated)
{
local int i;
for ( i=Array_Size(Anims)-1 ; i>=0 ; i-- )
if ( Anims[i].Animated == sAnimated )
return i;
return -1;
}Code: Select all
class DummyAnimActor expands Actor;
#exec OBJ LOAD FILE=..\Textures\RPG_Test_Sprite.utx
var SpriteAnimationManager AnimManager;
var SpriteAnimation WalkTest;
//Actor has been summoned
event PostBeginPlay()
{
ForEach AllActors (class'SpriteAnimationManager', AnimManager) //Find a animmanager
break;
if ( AnimManager == None ) //Create if not found
AnimManager = Spawn(class'SpriteAnimationManager');
//Hardcoded create
WalkTest = new( None, 'DummyAnimationObj') class'SpriteAnimation'; // ERROR: Error, Type mismatch in 'new' parent object
//Hardcoded time
WalkTest.DefaultAnimTime = 0.8;
//Hardcoded frames (dynamic arrays should allow this kind of accessors)
WalkTest.AnimFrames[0] = Texture'DownRightWalk3';
WalkTest.AnimFrames[1] = Texture'DownRightWalk4';
WalkTest.AnimFrames[2] = Texture'DownRightWalk5';
WalkTest.AnimFrames[3] = Texture'DownRightWalk6';
WalkTest.AnimFrames[4] = Texture'DownRightWalk7';
WalkTest.AnimFrames[5] = Texture'DownRightWalk8';
WalkTest.AnimFrames[6] = Texture'DownRightWalk1';
WalkTest.AnimFrames[7] = Texture'DownRightWalk2';
//Hardcoded two notifies
Array_Insert( WalkTest.AnimNotifies, 0, 2);
WalkTest.AnimNotifies[0].PlayOnFrame = 2;
WalkTest.AnimNotifies[0].CallOnFrame = 'FootstepSound';
WalkTest.AnimNotifies[1].PlayOnFrame = 6;
WalkTest.AnimNotifies[1].CallOnFrame = 'FootstepSound';
SetTimer( 10, true);
}
event Timer()
{
AnimManager.PlayAnimation( self, WalkTest, 1, 3, 'EndWalk' );
}
Now here we are at a part of where I feel my understanding of code is too shaky to be confident. SpriteAnimation is a smaller actor, which is supposed to contain an array of bitmaps and AnimNotifies (structs, containing a name [CallOnFrame] and int [PlayOnFrame]). This is where the issue lies, in SpriteAnimation with its only function, GetByPosition, which is supposed to return a float. At this point, I am left wondering what the issue is, but what should be happening is the current actor's texture is set to what ever should be occupying the result of GetByPosition's math, in its AnimFrames Bitmap Array. DummyAnimActor has set what should be in AnimFrames.