This post is a portion of Part 14 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- 14.0 – Finishing Our Game
- 14.1 – Adding Game States to our Allegro 5 Game
- 14.2 – Adding a Background to our Allegro 5 Game
- 14.3 – Adding Audio to our Allegro 5 Game
- 14.4 – Deploying our Allegro 5 Game in Visual Studio 2010
Full source code can be found here.
Hi Mike,
Your tutorial are awesome, and really helpful for me to complete my project.
But, I am wondering about how to make the game system PAUSE and CONTINUE again from the last session. Could you please give me some clue how to accomplish this?
thank so much before
Pause is really no different than any other state. Basically, you just have a state where you don’t update (and depending on your desire) where you don’t draw anything
thanks for replying, Mike
I am so glad that you notice my question
In my code, I add two states to accomplish this, one is PAUSE and just put some bitmap on it, and other is CONTINUE, which update the bullet and explosion, is this effective?
But I meet some problems on the sound.
I can’t pause the ambience sound when it is in the pause state.
Do you have a solution for this?
and the last, I put a line transition on the title’s bitmap, but although the whole bitmap doesn’t loaded completely, look like we can give a command on it.
I notice this when the bitmap is still loaded I try to press space bar, and when the bitmap has loaded completely it just directly go on to the game and the game look like has got some update…
I hope you understand my question, and sorry if my english is bad…
thank you so much
You can do a 2 state system like you are using. There is nothing wrong with that.
As far as pausing sound goes, in your “state machine” whenever you leave the playing state you can stop music. Whenever you enter the playing state you can start music. Then is works for pauses and game overs.
I don’t understand the third question. Can you maybe rephrase it?
But if I use the stop function “al_stop_sample_instance(…)”, it seems that the sound is playing at the start again. What I want is the sound continues playing at the section when I press the pause button, can it be like that?
The third question is about giving a transition to the title’s bitmap. It will be better if you can serve a tutorial about it. I think I just put it at the wrong place or section. I am confuse about it.
Thank you so much before…
You can “pause” the music by saving it’s position before stopping it, and then setting it’s position before starting it. http://www.allegro.cc/manual/5/al_get_sample_instance_position
I still don’t know what you mean by “giving a transition to the title’s bitmap”. Are you talking about moving an image? Or are you trying to fade the “Super Space Shooter” title screen out?
Sorry to make you confused. Yes, I want to fade in and fade out the title screen before it gets into the playing state. But I think something is misplaced.
And thanks so much, Mike. I have successfully implemented the pause section for the bgm.
hey mike i was implementing game states myself and i did not follow your videos on game state implementation but from what ive seen they are pretty similar, for some reason everything works the main menu, the game, and the gameover screen which actually has an option to where you can go back to the main menu and play another game. But one thing is bothering me i also have a pause implemented but when i change the gamestate to or from paused for some reason it terminates the program i have searched for a clue on how to fix this for a looong time (about three hours :)) but still havent found anything wrong and i cant seem to find out why it is doing this so please help me.
Can you email me your code?
sure whats ur email?
nm i found the contact me button
Hey!
You are using ship, bullets, comets and explosions variables in ChangeState method but You are not pasing them to it. How did You manage to compile it?
they are “global” objects, that’s the reason it works
Hey mate – just reading your comments from Rwinz Cyruz about adding a pause state. I have a question – im trying to implement what youve suggested but how can you save the current state your in so when you go back to playing state from pause it continues from where you paused from – currently if i change state to pause and have text drawn to the screen – when i change state back to playing the game resets.