|
-
[RESOLVED] Pause Menu (as2) using cs4
Ive been working on making a video game for quite some time now. I am pretty new at this, about 3 months ive been working on it, and things are going pretty well now. The only problem is I cant figure out how to do a pause menu yet. . I can make a pause menu easy enough, and should be able to figure out how to make it appear at the push of a button, but the problem is that I dont know how to make the action on my screen stop. If someone could help me, id greatly appreciate it. (if you need to see some part of my code, let me know, and Ill show whatever you need) By the way, I use onEnterFrame Logic. I think theres 2 diffeent way, and I dont know if this makes a diffedrence or not. Ive also looked online for a good guide on pausing the game, but googl wasnt able to help me there. IF someone doesnt know how to but knows where theres a goood guide that would be good as well (although helping me here would be better)
Last edited by TheBluePriest; 02-06-2010 at 09:36 PM.
-
Senior Member
Simplest way is to use 1 main enterFrame function to handle all the game logic. At the start of game set a variable gamePaused = false. Set it to true when game is paused. In your main enterFrame function before running rest of the code, simply check if that variable is true then return.
-
So I tried just doing that, but I have a problem when I try to put in the key logic
code:
function onEnterFrame(){
if (gamePaused == true)
if (Key.isDown (Key.80))//I get the error here
{gamePaused ==false;}
if (gamePaused == false){
if (Key.isDown (Key.80))//I get the error here too
{gamePaused ==true;}
if (_visible==true)
{//from here it goes on to the rest of my onEnterframe logic
but then for errors I get
')' or ',' expected
I dont quite get what Im doing wrong.
-
I figured it partially out. No more errors, but pushing p doesnt do anythign now, this is what it looks like
code:
function onEnterFrame()
{
if(gamePaused==true)
{
if(Key.getCode()==80)
{gamePaused==false}}
if(gamePaused==false){
if(Key.getCode() ==80)
{gamePaused == true}
also, i now have the pause screen will show up when i push p (not shown) so i know im doing something wrong with it not recognizing the p button
Last edited by TheBluePriest; 02-08-2010 at 11:38 AM.
-
PHP Code:
this.onEnterFrame=function(){ if(Key.isDown(80)){ if(!gamePaused){ gamepaused=true; //Show pause screen }else{ gamepaused=false; //Hide pause screen } } };
-
could you be a little more specific with that please? I dont have a clue where that would go. I tried just replacing it with my old code, but that didnt do anything. I set it to spacebar by the way instead of working with the ascII. But still pushing the pause button does nothing.
-
This would go on the frame where the "main" game is. Just to clear a few things up..
There isn't a sort of built in pause function within flash.. if you want a pause button in a game, you have to factor in absolutely everything that's going to stop when you press it. The variable "gamePaused" is just a name, it won't do anything until you tell the rest of your movie to respond to it.
So if you have a shooting game for example:
You have a function called "enemies", this might spawn an enemy in a random location when called.
You may also have a function called "shoot", this could be called when the mouse button is pressed and would fire a bullet and start a gun sound for example.
Now to effectively pause this game, you would have to disable both of those functions while the var "gamePaused" is true.. Assuming you have a movieclip that covers the whole stage, the first frame would be blank and the second frame would say "Paused" and cover the screen. This movie clip should stop on the second frame when "gamePaused" is true.
So back to the functions; The simplest way would be to write a condition at the top of each function which would be tested before the rest of the code in the function is executed:
function enemy(){
if(!gamePaused){
//enemy code
}
}
function shoot(){
if(!gamePaused){
//shooting code
}
}
So when either function is called, flash checks that the game isn't paused before it executes any of the code. If gamePaused is false (game is not paused) - it will continue with the function as normal. If gamePaused is true (game is paused) - it does nothing.
This is very simple example but should help you understand how a pause button would work. In a large, complex game, it'd be a lot of work. It's best to code with it in mind from the very beginning as it 'd be near impossible to slap in a pause button once it was nearing completion.
Last edited by lightspeed10; 02-09-2010 at 07:36 AM.
-
this is probably going to be a stupid question, but why are you using !gamePaused instead of just gamePaused? does the ! check that variable whether its true or false? That was my first thought, but then i started to doubt that once you said to put down !gamePaused for checking the enemy and ship code.
-
if(!gamePaused){
Is the same as putting
if(gamePaused == false){
Just a more efficient way of writing it.
Also, if(gamePaused){
Is the same as:
if(gamePaused == true){
-
ok, I got it, and I got the pause screen to work as well. My entire game pauses. thank you very much!
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|