Random anim

Posted:
Thu Dec 19, 2013 1:37 am
by barney12345
So im making a traffic game and I was fixing the graphics when I realised that I could either have only one animation used for that direction, (there is only one actor that clones itself after a timer) or I make lots more actors for all directions
so is there a way to randomly chose animations with the create actor function?
Re: Random anim

Posted:
Thu Dec 19, 2013 5:16 am
by AliceXIII
A simple approach would be using a switch and the rand() function.
Actor's Create Script:
- Code: Select all
int random=rand(4); //Equal's the max number of directions(animations)
char anim[50]; //Equal's max length in characters of the longest animation name
switch(random)
{
case 0:
strcpy(anim, "Actual Name01"); //Actual Name being the animation's real name
break;
case 1:
strcpy(anim, "Actual Name02");
break;
etc..
etc..
}
CreateActor("actor name", anim, "parent name", "path name", "xpos", "ypos", "abspos");
This should work with no problem just let me know if you run into any or if i did something wrong!
Re: Random anim

Posted:
Thu Dec 19, 2013 5:41 am
by skydereign
And since it sounds like you are wanting to set the animation randomly at create, you can do this (because you have access to the event actor's animations) in the create actor event of the light.
- Code: Select all
ChangeAnimation("Event Actor", getAnimName(rand(4)), FORWARD);
// change 4 to however many animations the actor has