Random anim

You must understand the Game Editor concepts, before post here.

Random anim

Postby barney12345 » Thu Dec 19, 2013 1:37 am

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?
Darth Vader called... he wants his cookies back
User avatar
barney12345
 
Posts: 122
Joined: Wed Nov 07, 2012 6:52 am
Location: A land down under
Score: 4 Give a positive score

Re: Random anim

Postby AliceXIII » Thu Dec 19, 2013 5:16 am

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!
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Random anim

Postby skydereign » Thu Dec 19, 2013 5:41 am

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron