Animate background images one time

Started by Ghostlady, Sat 02/11/2024 18:55:14

Previous topic - Next topic

Ghostlady

I have four background images that I would like to animate just once.  It does it repeatedly.  How can I do this?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

CaptainD

You could create a View with the 4 fullscreen sprites, create an object and set it to that view, then animate it once.

ie
Code: ags
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

Ghostlady

I want to animate the backgrounds not an image, but only for one cycle.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Crimson Wizard

#3
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
if (GetBackgroundFrame() == LAST_FRAME_NUMBER)
{
    SetBackgroundFrame(LAST_FRAME_NUMBER); // this fixes it on the last frame
}

Ghostlady

Yes, this is what I was looking for.
So I set it up like this: 
Code: ags
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.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Crimson Wizard

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

Khris

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()

Ghostlady

CW - Here is the alligator, it is part of the background.

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

Thanks for your ideas Kris!
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Crimson Wizard

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

Rik_Vargard

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

Crimson Wizard

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.

Ghostlady

Ok, thanks for all this. I'll do some switching things around.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk