Page 1 of 1

function ChangeAnimIndex() & DIRECTION by number

PostPosted: Fri Aug 01, 2008 4:43 am
by feral
In response to a call in the request forum


simple version - changes the animation using the indexnumber - PLUS UPDATED VERSION IN LAST POST (includes direction)

void ChangeAnim(int anim)
{
char *temp=getAnimName(anim);
ChangeAnimation("Event Actor",temp,NO_CHANGE);
}


must be used in the event(s) of the actor being changed.
to use

ChangeAnim(var); //where var is the index number of the animation
or
ChangeAnim(6); //changes to animation index 6

more complex version next...

Re: function ChangeAnimIndex() by number

PostPosted: Fri Aug 01, 2008 4:55 am
by feral
harder version

this one allows you to change the animation of any actor using animation index numbers.
However, i don't know how to pass the macros FORWARD,REVERSE etc so the direction is hard coded to NO_CHANGE

global function
Code: Select all

void ChangeAnim(char *actor,int anim)
{
char *temp=getAnimName(anim);
ChangeAnimation(actor,temp,NO_CHANGE);
}


to use
ChangeAnim("actorname",2); //where actorname is the name of the actor ( as a string) to change works on clonenames etc

an even more complex version to follow which allows you to control the actual order of the animation index

Re: function ChangeAnimIndex() by number

PostPosted: Fri Aug 01, 2008 4:58 am
by feral
A simple way to change animations using the animation name only

in global
void ChangeAnim(char *string)
{
ChangeAnimation("Event Actor",string, NO_CHANGE);
}

In draw actor OF event actor
ChangeAnim("fire");

however if you want to use maths to swap them
ie:
animindex=animindex+1


because if you delete an animation and add it again later it may not be the same index number..

Using maths to cycle thru or select an animation index

to do this you really need to setup your own index (which is a good idea anyway, because of the when animations are deleted and rebuilt later the animation index can can get out of order)

so
in global
create a string array large enough to hold all your animations for a character
Code: Select all
char *player_animindex[10]; //for 10 animations


then in the "create actor" of the player
setup the index ( this gives you control of the order of the index as well..which helps when using maths)

Code: Select all
player_animindex[0]="runleft"; //actual name of the animations ie as used in ChangeAnimation
player_animindex[1]="runright";
player_animindex[2]="die";
player_animindex[3]="shoot";


then create a global function

Code: Select all
void ChangeAnim(int index)
{
ChangeAnimation("Event Actor",player_animindex[index], NO_CHANGE);
}


now to change the animindex in the draw event of the player

Code: Select all
ChangeAnim(2); // or the desired index
or
ChangeAnim(variable); // where variable =  the desired index and can then be modded using maths/logic etc



of course this only works for the player( or a particular actor) .. and must be called in the draw event of the player,/actor but if it looks useful I can make it more generic so you can call animations for any actor.. let me know..

Re: function ChangeAnimIndex() & DIRECTION by number

PostPosted: Sat Aug 02, 2008 8:29 pm
by feral
UPDATED VERSION

This function allows you to change the animation using numbers/vars and alllows the direction to be changed

Code: Select all
void ChangeAnim(int anim,const int dir)
{
char *temp=getAnimName(anim);
ChangeAnimation("Event Actor",temp,dir);
}


TO USE:
in the draw event of the actor to be changed
use
Code: Select all
ChangeAnim(index,direction);


where index is a integer (the animantion index)
and direction = FORWARD,BACKWARD,STOPPED,NO_CHANGE

OR, you can use numbers(or other vars) for the directions - see below

sorry my fault, I knew it worked this way but coded it wrong when I first tested it, so thought it didn't work, but it does :D

the directions are #defines in GE where
FORWARD=4
BACKWARD=5
STOPPED=6
NO_CHANGE=8

so ChangeAnim(1,5); will change animation to 2nd animation and backward direction

use the above with any combination of the other ideas in this thread to get what you need :D
cheers
feral