Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: khnum on Sat 07/04/2007 12:18:06

Title: Starting an animation after .SetAsPlayer (SOLVED)
Post by: khnum on Sat 07/04/2007 12:18:06
So, i' making a gui to switch between different characters, and when you click on the image of the character you want to switch to, an animation starts; anyway, if the character is in the same room, there are no problems, but if the player is in another room, the room changes after the animation (and i want it to start after the room change). Since setAsPlayer waits for the entire function to finish before switching, what can i do?
Title: Re: starting an animation after setAsPlayer
Post by: Scorpiorus on Sat 07/04/2007 13:55:18
You can work around it by setting a flag variable instead of starting an animation on clicking the image.
Then you can check for that flag in the repeatedly_execute() event function of the main global script and run animation from there:

At the top of the main global script:

bool bRunAnimation = false;



on clicking the image:

cSomeCharacter.SetAsPlayer();
bRunAnimation = true;


repeatedly_execute()

if ( bRunAnimation == true )
{
    < start animation here >

    bRunAnimation = false; // to avoid starting it repeatedly
}
Title: Re: starting an animation after setAsPlayer (solved)
Post by: khnum on Sat 07/04/2007 14:15:21
Thanks Scorpius, it worked  :D
Title: Re: starting an animation after setAsPlayer (solved)
Post by: Scorpiorus on Sat 07/04/2007 14:30:47
You are welcome :)

Ah and one thing to add: if you were running different animations for different images, you can reproduce it with if-else within repeatedly_execute taking a current value of the player variable as condition to check for:

repeatedly_execute()

if ( bRunAnimation == true )
{
    if      (player == cEgo1)  < start cEgo1-specific animation here >;
    else if (player == cEgo2)  < start cEgo2-specific animation here >;
    else if (player == cEgo3)  < start cEgo3-specific animation here >;

    bRunAnimation = false; // to avoid starting it repeatedly
}