Start animation on a specific frame

Started by TheManInBoots, Wed 25/09/2019 13:40:43

Previous topic - Next topic

TheManInBoots

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!

Mandle

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.

Crimson Wizard

#2
deleted

eri0o

#3
I gave a try, not sure how well it works.

CoolAnimate.ash
Spoiler
Code: ags

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


CoolAnimate.asc
Spoiler
Code: ags

// 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

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

Crimson Wizard

#4
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).

Mandle

You are still my favorite wizard!!!

(Gandalf comes a close second though)

TheManInBoots

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!!  :)

TheManInBoots

#7
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.

TheManInBoots

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!


Amir

I had this problem with a few animations too. But I did the animation separately, and its not time consuming.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

TheManInBoots

Thanks I downloaded the new version.

TheManInBoots

#12
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.

SMF spam blocked by CleanTalk