Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: bx83 on Wed 09/08/2017 13:17:13

Title: Animate NoBlocking happens and finishes instantly...?
Post by: bx83 on Wed 09/08/2017 13:17:13
Hi there,
Been playing with animation. I want to have a background character:
1. choose a random number
2. choose animation based on number
3. play the animation, NO blocking; so it plays in the background
4. while it's animating, don't allow the routine to choose another animation.

Code for this is:

function room_RepExec()
{
if (cPig.Animating==false) {
PigRandAnim=Random(2);
if (PigRandAnim==1) { //idle
cPig.LockView(53);
cPig.Animate(1, 1, eOnce, eNoBlock);
cPig.UnlockView();
Display("finished normal view");
} else if (PigRandAnim==2) { //drinking
cPig.LockView(5);
cPig.Animate(1, 1, eOnce, eNoBlock);
cPig.UnlockView();
Display("finished drinking view");
}
}
}


But this doesn't work - I just get constant reminders that "finished <something> view", the animation doesn't actually occur.

If I do eBlocking, everything works fine; but I can't do anything since this isn't happening in the background, and stops everything else.

IdleView and NormalView are set. I've tried with MovementLinkedToAnimation as true and false, no dice.

I feel like this has something to do with NormalView showing only frame 0 if not moving (character never moves); but I can't get my head around it. Maybe you can help?

Title: Re: Animate NoBlocking happens and finishes instantly...?
Post by: bx83 on Wed 09/08/2017 13:37:09
(drinking==normal)
Title: Re: Animate NoBlocking happens and finishes instantly...?
Post by: Kitty Trouble on Wed 09/08/2017 14:29:29
What happens if you take the cPig.UnlockView(); line from both the if statements and move it to the beginning of each if statement instead of the end? (Just speculation)
Title: Re: Animate NoBlocking happens and finishes instantly...?
Post by: Crimson Wizard on Wed 09/08/2017 15:01:35
You are using eNoBlock command. This means that after command is run it does not wait until animation finished, and continue executing next commands. This is why it locks view and unlocks view almost immediately.

Usual solution is to remember that animation was started, and then keep checking Animating property to know when its finished, and then unlock the view.
You are already checking for Animating, so there is just one small change that must be done:

EDIT: basically, almost what Morgan LeFlay said :).

Code (ags) Select

function room_RepExec()
{
        if (cPig.Animating==false) {
                // cPig.UnlockView(); // maybe not even needed
                PigRandAnim=Random(2);
                if (PigRandAnim==1) {   //idle
                        cPig.LockView(53);
                        cPig.Animate(1, 1, eOnce, eNoBlock);
                } else if (PigRandAnim==2) {    //drinking
                        cPig.LockView(5);
                        cPig.Animate(1, 1, eOnce, eNoBlock);
                }
        }
}


In fact, I am not even sure if UnlockView ought to be called in such case, since Pig keeps animating forever anyway. Maybe you can just throw this command out?
Depends on whether AGS requires you to unlock the view before locking to another.