Author Topic: Start animation where it stopped  (Read 322 times)

Start animation where it stopped
« on: 29 Nov 2017, 11:30 »
How can I start my object animation from the same frame where I stopped it? For example, let's say I have an animated spinning wheel that loops repeatedly with NoBlock on. When I click it, it stops instantly in it's current frame. This is great. Now when I click it again using the "Animate"-command, it jumps to the first frame of the loop, which is bad. I want it to continue from the same frame where it stopped.

Plan B would be to wait that the loop is finished and stop it then, but it's not what I'm really looking for. I want the actions to be instantaneous.

Couldn't find any answer for this, so any help is welome!

Slasher

  • slasher
    • I can help with AGS tutoring
    •  
    • Lifetime Achievement Award Winner
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • Slasher worked on a game that was nominated for an AGS Award!
Re: Start animation where it stopped
« Reply #1 on: 29 Nov 2017, 12:13 »
How many Frames are there?

Something possibly like this:

After you stop the wheel you could do a Frame check and set it as SetView.

Code: Adventure Game Studio
  1. }
  2. if(!wheel.Animting) // when you have stopped the wheel
  3.    if(Frame==0){
  4.    oWheel SetView(6,0,0)// Will show oWheel View 6 Loop 0 Frame 0. oWheel being what your object name or ID}
  5. }
  6.    else if(Frame==1){
  7.    oWheel SetView(6,0,1)// Will show oWheel View 6 Loop 0 Frame 1. oWheel being wjat your object name or ID}
  8.  
  9.  // etc etc
  10. }
  11. }
  12.  

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Start animation where it stopped
« Reply #2 on: 29 Nov 2017, 12:21 »
Afaik this isn't possible using the Animate() or some other command; you have to manually change the object's sprite.

Say the wheel sprites are in slots 134 to 145.

Code: Adventure Game Studio
  1. int delay = 3; // animation delay
  2. bool spinning;
  3. int frame = 0, frame_delay = 0;
  4.  
  5. function room_RepExec() {
  6.   if (spinning) {
  7.     frame_delay = (frame_delay + 1) % delay;
  8.     if (frame_delay == 0) {
  9.       frame = (frame + 1) % 12; // 12 frames
  10.       oWheel.Graphic = frame + 134;
  11.     }
  12.   }
  13. }

Now you can start/stop the wheel by setting spinning to [/i]true/false[/i].

Re: Start animation where it stopped
« Reply #3 on: 29 Nov 2017, 12:45 »
Thanks Slasher & Khris for the quick answers!

Yes, I was afraid that I cant use the animate-command. I have 25 frames so custom manipulation with the views seems complicated. But I did a quick test with the script and it seems to work fine, so I'll use it for now and report back if there is trouble. Thanks Khris!

Solved! ;-D


Slasher

  • slasher
    • I can help with AGS tutoring
    •  
    • Lifetime Achievement Award Winner
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • Slasher worked on a game that was nominated for an AGS Award!
Re: Start animation where it stopped
« Reply #4 on: 29 Nov 2017, 13:08 »
You can use the StopAnimating();command and check from there.

But as you say, you have quite a few frames.

Khris' solution is neat and a lot less work (nod)