Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ghostlady on Sat 02/11/2024 18:55:14

Title: Animate background images one time
Post by: Ghostlady on Sat 02/11/2024 18:55:14
I have four background images that I would like to animate just once.  It does it repeatedly.  How can I do this?
Title: Re: Animate background images one time
Post by: CaptainD on Sat 02/11/2024 20:25:49
You could create a View with the 4 fullscreen sprites, create an object and set it to that view, then animate it once.

ie
object[1].SetView(14);
object[1].Animate(0, 3, eOnce, eBlock, eForwards);

I assume you mean you want to animate the entire background. You can set it to either blocking or non-blocking, depending on the effect you want.

Manual link for more info:

https://adventuregamestudio.github.io/ags-manual/Object.html
Title: Re: Animate background images one time
Post by: Ghostlady on Sat 02/11/2024 20:30:56
I want to animate the backgrounds not an image, but only for one cycle.
Title: Re: Animate background images one time
Post by: Crimson Wizard on Sat 02/11/2024 20:35:24
Quote from: Ghostlady on Sat 02/11/2024 20:30:56I want to animate the backgrounds not an image, but only for one cycle.

There's a command that allows to switch frames or start/stop animation by hand:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Room.html#setbackgroundframe

With this you could wait until last frame is reached, and stop it on the current frame.

Do you want to animate this in a blocking manner, where it pauses everything else, or keep the game running?
Do you want to repeat this process periodically at some points, or only once after a room is entered? Or once at some point?
The final code would depend on answers to these questions

For example, if you want this to be a non-blocking animation, then you may do this in room's Repeatedly Execute function:
Code (ags) Select
if (GetBackgroundFrame() == LAST_FRAME_NUMBER)
{
    SetBackgroundFrame(LAST_FRAME_NUMBER); // this fixes it on the last frame
}
Title: Re: Animate background images one time
Post by: Ghostlady on Sun 03/11/2024 02:08:26
Yes, this is what I was looking for.
So I set it up like this: 
function room_RepExec()
{
  if (GetBackgroundFrame() == 2)
{
    SetBackgroundFrame(2); // this fixes it on the last frame  }
}
}

Here's the scenario.  There is an alligator on the background screen with his mouth closed. The second background his mouth is halfway open, on the third background it is open all the way.  There are two sounds playing, the alligator making his noises and background swamp noises like birds.  I would like to check for the alligator sound (aSound31) to see if it has ended.  If it has, I would then like to close the gator's mouth so I would use another SetBackgroundFrame(0) when this happens.  I can't figure out to how to check for when the sound ends.

Also, the second player will need to pass this way also. I am assuming it should react the same way for the second player.
Title: Re: Animate background images one time
Post by: Crimson Wizard on Sun 03/11/2024 10:12:11
How big is the alligator compared to the room? Room background animations are usually meant for changing WHOLE room looks, like day-night cycles, or complex animations which affect whole background (example: it's raining with water drops and streams everywhere).

If alligator is just a piece in the room, then it's better to use Room Object for that. Room objects have Animate command that can run back and forth, once or repeated, or get locked on particular image.
Title: Re: Animate background images one time
Post by: Khris on Sun 03/11/2024 17:10:38
To find out when a sound has ended, store its channel when playing the sound, the repeatedly check if the channel is still playing.
Or you can simply set a timer to a number corresponding to the sound effect's length and use IsTimerExpired()
Title: Re: Animate background images one time
Post by: Ghostlady on Sun 03/11/2024 19:44:09
CW - Here is the alligator, it is part of the background.

https://www.youtube.com/watch?v=EtSvp3PuPdc

Thanks for your ideas Kris!
Title: Re: Animate background images one time
Post by: Crimson Wizard on Sun 03/11/2024 20:34:17
Quote from: Ghostlady on Sun 03/11/2024 19:44:09CW - Here is the alligator, it is part of the background.

https://www.youtube.com/watch?v=EtSvp3PuPdc

This alligator is less than 1/10 of the game screen! it's not optimal to use full background frames to animate that. I would advise redoing it as a room object.
You may achieve that by simply cutting out identical pieces of background frames and reimporting these as sprites.
Title: Re: Animate background images one time
Post by: Rik_Vargard on Sun 03/11/2024 20:46:12
Quote from: Crimson Wizard on Sun 03/11/2024 20:34:17This alligator is less than 1/10 of the game screen! it's not optimal to use full background frames to animate that. I would advise redoing it as a room object.
You may achieve that by simply cutting out identical pieces of background frames and reimporting these as sprites.

I agree with this. Not only could you make it just an animated object, but objects can have so many more frames, so you can have a smoother animation.
And also, when you animate an object "eOnce", the last frame will be that object's image after the animation. 
Title: Re: Animate background images one time
Post by: Crimson Wizard on Sun 03/11/2024 21:17:19
Quote from: Rik_Vargard on Sun 03/11/2024 20:46:12I agree with this. Not only could you make it just an animated object, but objects can have so many more frames, so you can have a smoother animation.
And also, when you animate an object "eOnce", the last frame will be that object's image after the animation. 

Yes, and furthermore, with Object animations you may link sounds to the frames. Which means you don't have to play sounds by separate commands and script waiting for them to complete. If linked to frames they will play automatically. You may configure animation frames to have necessary delay before playing next frame, which will also solve the "waiting for sound to complete" problem.
Title: Re: Animate background images one time
Post by: Ghostlady on Mon 04/11/2024 01:15:21
Ok, thanks for all this. I'll do some switching things around.