Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TheManInBoots on Wed 25/09/2019 13:40:43

Title: Start animation on a specific frame
Post by: TheManInBoots on Wed 25/09/2019 13:40:43
Hello all!

What ideas do you guys have for starting an animation from a specific frame on, and not from the beginning?

I have some quirky or creative solutions, but if anyone else has their own way of doing it or any ideas, I'd be really curious to hear about it, if anyone ever came across that problem.

I would need to pause and play an animation very, very flexibly and very fast for what I'm trying to do, so the ideas I have so far are really sub-optimal.
So if you have any basic approaches  or ideas, I'd greatly appreciate it!
Title: Re: Start animation on a specific frame
Post by: Mandle on Thu 26/09/2019 01:54:54
I don't know if there is a coding way to do this but, if not, the obvious solution would be to create a bunch of views, each starting the animation from a different frame and then change the sprite's view to the specific one when needed.

This won't work well with really long animations of course, but for 10 or so frames should be doable.
Title: Re: Start animation on a specific frame
Post by: Crimson Wizard on Thu 26/09/2019 02:23:53
deleted
Title: Re: Start animation on a specific frame
Post by: eri0o on Thu 26/09/2019 03:26:18
I gave a try, not sure how well it works.

CoolAnimate.ash (https://gist.github.com/ericoporto/cbe5e8b2f3444fe9371a4b24d640d925#file-coolanimate-ash)
Spoiler
Code (ags) Select

import void CoolAnimate(this Character*, int view, int loop, int frame,  int delay, BlockingStyle blockStyle);
[close]


CoolAnimate.asc (https://gist.github.com/ericoporto/cbe5e8b2f3444fe9371a4b24d640d925#file-coolanimate-asc)
Spoiler
Code (ags) Select

// new module script
managed struct CoolAnimateData{
  bool animating;
  int delay;
  int count;
};

CoolAnimateData* coolData[];

void game_start(){
  coolData = new CoolAnimateData[Game.CharacterCount];
  for(int i=0; i<Game.CharacterCount; i++){
    coolData[i] = new CoolAnimateData;
  }
}

void repeatedly_execute_always(){
  for(int i=0; i<Game.CharacterCount; i++){
    if(coolData[i].animating){   
      if(coolData[i].count>coolData[i].delay){
        coolData[i].count = 0;
             
        int frame = character[i].Frame+1;
     
        if(frame < Game.GetFrameCountForLoop(character[i].View, character[i].Loop)){               
          character[i].LockViewFrame(character[i].View, character[i].Loop, frame);
        } else {
          coolData[i].animating = false;
          character[i].UnlockView(eKeepMoving);
        }
     
      } else {
        coolData[i].count++;
      }     
    }
  }
}

void CoolAnimate(this Character*, int view, int loop, int frame,  int delay, BlockingStyle blockStyle){
  this.LockViewFrame(view, loop, frame);
  coolData[this.ID].delay = delay;
  coolData[this.ID].count = 0;
  coolData[this.ID].animating = true;

  if(blockStyle == eBlock){
    int frame_count = Game.GetFrameCountForLoop(view, loop);
    for (int i=0; i<frame_count; i++){
      Wait(delay);
    }
  }
}
[close]


You use this module by just calling it in your character like

Code (ags) Select

function hGlowingOrb_AnyClick() {
  cEgo.CoolAnimate(VIEW1 /* view */, 2 /* loop */, 3 /* frame */, 5 /* delay */, eBlock);
}


I assumed you needed this for a character, if it's for something else, you have to figure out something else :P
Title: Re: Start animation on a specific frame
Post by: Crimson Wizard on Thu 26/09/2019 20:30:33
Seeing that it's trivial to add in the engine but requires much hassle in script, I am considering adding this ability to the engine, to AGS 3.5.0.

I don't really like doing this, since the version is almost out, but it appeared to be possible to complete in just couple of hours (spent 1 hour discussing how it should work).
Title: Re: Start animation on a specific frame
Post by: Mandle on Fri 27/09/2019 03:58:10
You are still my favorite wizard!!!

(Gandalf comes a close second though)
Title: Re: Start animation on a specific frame
Post by: TheManInBoots on Fri 27/09/2019 23:27:30
Quote from: Mandle on Thu 26/09/2019 01:54:54
I don't know if there is a coding way to do this but, if not, the obvious solution would be to create a bunch of views, each starting the animation from a different frame and then change the sprite's view to the specific one when needed.

This won't work well with really long animations of course, but for 10 or so frames should be doable.

It's a great idea, but it's not really ideal for what I try to do. Thanks for sharing though!!  :)
Title: Re: Start animation on a specific frame
Post by: TheManInBoots on Fri 27/09/2019 23:28:30
That's dope eri0o!
Thanks for taking the time to write this.
I like the name coolanimate.
I let you know how it works after I experimented with it.
Title: Re: Start animation on a specific frame
Post by: TheManInBoots on Fri 27/09/2019 23:28:58
Quote from: Crimson Wizard on Thu 26/09/2019 20:30:33
Seeing that it's trivial to add in the engine but requires much hassle in script, I am considering adding this ability to the engine, to AGS 3.5.0.

I don't really like doing this, since the version is almost out, but it appeared to be possible to complete in just couple of hours (spent 1 hour discussing how it should work).

You rock, Crimson Wizard!
Title: Re: Start animation on a specific frame
Post by: Crimson Wizard on Tue 01/10/2019 09:00:17
Wanted to mention, the 3.5.0 RC1 is posted and it has this feature now ready for testing: https://www.adventuregamestudio.co.uk/forums/index.php?topic=57133.msg636611285#msg636611285
Title: Re: Start animation on a specific frame
Post by: Amir on Sat 05/10/2019 10:48:38
I had this problem with a few animations too. But I did the animation separately, and its not time consuming.
Title: Re: Start animation on a specific frame
Post by: TheManInBoots on Tue 22/10/2019 11:55:42
Thanks I downloaded the new version.
Title: Re: Start animation on a specific frame
Post by: TheManInBoots on Sat 11/04/2020 22:46:23
eri0o,
I know this is super late, but I promised I would let you know how your script works.
I was just too busy to take a look, so, since I finally got to it:

It works fine, but the blocking part does not.