Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Wait for Animation to Finish

Author
Message
Master SeePlusPlus
13
Years of Service
User Offline
Joined: 30th Dec 2012
Location:
Posted: 28th May 2014 17:51
Hey,

Basically I am currently working on a video game where I have a video playing as the introduction. Unfortunately, when it is playing the program is still running, so the game will start while the video is on the screen.

I have tried doing:

load animation "blahblahblah.avi",1
play animation 1
while spacekey()=0
endwhile

and MANY variations of this using wait keys so other methods, but when I do that the screen stays black and the animation will pop up with the video game on space key. What should I do if I want the program to wait for the animation to finish before continuing?

Thank you!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th May 2014 18:34
You need to insert a loop that waits for the animation to finish. Here's one way to do it:





Powered by Free Banners
Master SeePlusPlus
13
Years of Service
User Offline
Joined: 30th Dec 2012
Location:
Posted: 29th May 2014 16:46
Thank you very much! I find it strange that this works but a while loop was giving me issues. Of course, it may have been I did not have a sync command in. Anyways, thank you very much!

/Solved
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th May 2014 18:31
Quote: "I find it strange that this works but a while loop was giving me issues. Of course, it may have been I did not have a sync command in."


Works fine for me with or without the syncs or while loops. Perhaps there was something else wrong?

Could you provide a short snippet showing the method you were trying to use? We might as well get to the root of this problem now before it pops up somewhere else in a different context.



Powered by Free Banners
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 29th May 2014 20:36
Another method could be as simple as knowing the length of your animation and using a timer.

For example, if your animation is 10.2 seconds long:

play animation 1
t#=timer()+10200
while t#>timer()
endwhile


666GO†O666
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th May 2014 21:33


TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th May 2014 21:34
That wouldn't be consistent over multiple computers, because DBP times animations by framerate, not by real time.

Your dungeon has been arrested by a signature image because it tried to be a mod
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th May 2014 01:41
Quote: "That wouldn't be consistent over multiple computers, because DBP times animations by framerate, not by real time."


What do you mean?

An animation that is 10 seconds long is 10 seconds long regardless of frame rate.

What is true though is that the screen image is only updated at the frame rate so on slow systems many animation frames will be skipped - but the overall duration remains the same (apart from inaccuracies arising from the skipping). The animation's audio isn't affected as far as I can tell.



Powered by Free Banners
Master SeePlusPlus
13
Years of Service
User Offline
Joined: 30th Dec 2012
Location:
Posted: 30th May 2014 03:32 Edited at: 30th May 2014 03:33
I was using something to the effect of this:



I figured it would wait to continue until it was done playing. I am still getting used to differences in the way DBPro interprets loops vs raw languages like java or C++

another thing I tried was:



or something like that. Yours worked, however, so thanks
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th May 2014 09:49 Edited at: 30th May 2014 09:54
@Master SeePlusPlus



Never do that! (Scream followed by face palm) The first example you created looks better; however is still going to overload your hardware, but not quite as severely as the first. Prevent overloads by inserting a sync call in the loop like GG did or even better a call to Matrix1 Nice Sleep. That will dedicate more CPU processing for playing the animation smoothly; take a look at your process CPU usage in the task manager.

@Derek Darkly

Your timer example is fine but it requires the animation to continue playing without lag.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th May 2014 14:58
Quote: "I was using something to the effect of this:"


Strange. That works fine for me. Anyway, including sync on in your program and then syncing as required is a safer option.

Quote: "another thing I tried was:"


As Chris Tate says, please don't do that. In fact I'm amazed anything like that works - it's asking for a stack overflow and even if it doesn't you'll be left with loads of unterminated gosub references on the stack when the animation eventually ends.



Powered by Free Banners
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 30th May 2014 21:43
I code on an old Dell Dimension 2300 which runs at a whopping 55-60 FPS in a blank loop.

That said, and as a hobbyist, I don't code with laggy computers in mind. (I test on a Dell E521 at work.) If someone can't play a simple intro animation without lag, how can they expect to enjoy a decent game anyway?

Again though, I'm a hobbyist not a pro developer so my mindset is a little more lax. Just my 2 pesos.

666GO†O666
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 31st May 2014 00:34 Edited at: 31st May 2014 00:35
Correct, as a hobbyist you are just having fun. I do not code with laggy computers in mind either; that can lead to premature optimization; what I mentioned was more about prevention of running the game before the animation finishes, not knowing what video playback hardware the player has; some can be bad (that is the video playback, not the game playback).

Login to post a reply

Server time is: 2026-07-05 17:55:50
Your offset time is: 2026-07-05 17:55:50