Higor coded a SpriteAnimation actor and a SpriteAnimationManager. But I have a Type Mismatch error in SpriteAnimationManager, and he is making XC engine.
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:
SpriteAnimation
Code: Select all
class SpriteAnimation expands Object;
struct AnimNotify
{
var name CallOnFrame;
var int PlayOnFrame;
};
var float DefaultAnimTime;
var array<BitMap> AnimFrames;
var array<AnimNotify> 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 ];
}
SpriteAnimationManager
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<AnimRegister> Anims;
event Tick( float DeltaTime)
{
local int i, Max;
local float OldPosition;
local bool bRemove;
Max = Array_Size( Anims);
for ( i=0 ; i<Max ; i++ )
{
if ( Anims[i].Animated == none || Anims[i].Animated.bDeleteMe ) // Animated actor has been removed, so remove its Array. This actor is instantiated pre or post begin play?
{
REMOVE_ANIMATION:
Array_Remove( Anims, i, 1);
Max--;
i--;
continue;
}
bRemove = false;
OldPosition = Anims[i].CurPosition; // This holds a value for animation playing, seen below.
Anims[i].CurPosition += Anims[i].AnimRate * DeltaTime; // This is how an animation plays a cycle.
if ( Anims[i].bNotify )
{} //PROCESS NOTIFIES!!!!
if ( (abs(OldPosition) < 1) && (abs(Anims[i].CurPosition) >= 1) ) // Animation has completed a cycle
{
if ( !Anims[i].bLooping && (Anims[i].RepeatCount-- <= 0) )
{
Anims[i].Animated.Texture = Anims[i].Animation.GetByPosition(1); // Error, Type mismatch in '='
goto REMOVE_ANIMATION;
}
Anims[i].CurPosition -= int(Anims[i].CurPosition); //Why not substract 1?... imagine the animation plays so fast it completes multiple cycles per frame... get it?
}
Anims[i].Animated.Texture = Anims[i].Animation.GetByPosition( Anims[i].CurPosition); // Error, Type mismatch in '='
}
}
function bool StopAnimation( Actor sAnimated)
{
local int Idx;
Idx = GetByActor( sAnimated);
if ( Idx >= 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;
}
DummyAnimActor
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.
Can anyone help me? Otherwise what is basically the whole reason I began coding is on a shelf. He gave me this code and I was able to use it to study (led to a bunch of information on bitmaps, dynamic arrays, the new() function which is an interesting one, and some interesting things I can do with tick), but if I can't get it to work then we can't get into the next step of this.