Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 02-19-2009, 09:57 PM   #1
M1KE
Senior Member
 
Join Date: Feb 2009
Posts: 143
Unhappy [AS2] Pausing then unpausing a game

Hi! I have a game hear that I need to unpause and pause it with the letter p (key 80). The pausing works and the unpausing works but you have to be quick. For instance if you hold down p for a long period of time it flash between the paused state and the unpaused state. Is there a way how I can set a time here is what i have:

function Pause() {
if (Key.isDown(80)) {
if (Paused) {
setInterval(Pause,3000)
Paused = false;
} else {
Paused = true;
setInterval(Pause,3000)
}
}
if (Paused) {
_root.Pac.Move = false;
_root.Pac.gotoAndStop(1);
_root.Monster1.Move = false;
_root.Monster2.Move = false;
_root.Monster3.Move = false;
_root.Monster4.Move = false;
_root.Monster5.Move = false;
_root.Pac._alpha = 15;
_root.PauseText._alpha = 100;
_root.Monster1._alpha = 15;
_root.Monster2._alpha = 15;
_root.Monster3._alpha = 15;
_root.Monster4._alpha = 15;
_root.Monster5._alpha = 15;
_root.Food._alpha = 15;
} else if (Paused == false) {
_root.Pac.play();
_root.Pac.Move = true;
_root.Monster1.Move = true;
_root.Monster2.Move = true;
_root.Monster3.Move = true;
_root.Monster4.Move = true;
_root.Monster5.Move = true;
_root.Pac._alpha = 100;
_root.PauseText._alpha = 0;
_root.Monster1._alpha = 100;
_root.Monster2._alpha = 100;
_root.Monster3._alpha = 100;
_root.Monster4._alpha = 100;
_root.Monster5._alpha = 100;
_root.Food._alpha = 100;
}
}
I'm trying to make it pausing when you press 'p' but you can't unpause it till 3 seconds later to stop the flash thing. the function 'Pause is then put in the actions for Pac. 9If you've guesseed this is a Pac man sort of game.
Thanks in advance!
M1KE is offline   Reply With Quote
Old 02-20-2009, 02:29 PM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

You put this in an onEnterFrame method? I think you can put it in an onKeyDown.
rrh is offline   Reply With Quote
Old 02-20-2009, 03:16 PM   #3
PhatKitty
Registered User
 
Join Date: Jan 2009
Posts: 30
Default

Maybe use a Boolean variable instead of a function? I'm kinda new to AS so it might be wrong

ActionScript Code:
var Paused:Boolean = false if (Key.isDown(80)) { Paused = true; } if (Paused == true) { if (Key.isDown(80)) { Paused = false; } _root.Pac.Move = false; _root.Pac.gotoAndStop(1); _root.Monster1.Move = false; _root.Monster2.Move = false; _root.Monster3.Move = false; _root.Monster4.Move = false; _root.Monster5.Move = false; _root.Pac._alpha = 15; _root.PauseText._alpha = 100; _root.Monster1._alpha = 15; _root.Monster2._alpha = 15; _root.Monster3._alpha = 15; _root.Monster4._alpha = 15; _root.Monster5._alpha = 15; _root.Food._alpha = 15; } else if (Paused == false) { _root.Pac.play(); _root.Pac.Move = true; _root.Monster1.Move = true; _root.Monster2.Move = true; _root.Monster3.Move = true; _root.Monster4.Move = true; _root.Monster5.Move = true; _root.Pac._alpha = 100; _root.PauseText._alpha = 0; _root.Monster1._alpha = 100; _root.Monster2._alpha = 100; _root.Monster3._alpha = 100; _root.Monster4._alpha = 100; _root.Monster5._alpha = 100; _root.Food._alpha = 100; }

This would mean (I think) that when you press p it pauses, and when you press it again it unpauses, so you don't need an interval, unless you wanted an interval?

And sorry if this is completely wrong
PhatKitty is offline   Reply With Quote
Old 02-20-2009, 03:44 PM   #4
M1KE
Senior Member
 
Join Date: Feb 2009
Posts: 143
Default

The Boolean thing half worked because it paused it and didn't flash between the two states but the only problem was that you had to hold down the p key to keep it paused
M1KE is offline   Reply With Quote
Old 02-20-2009, 03:56 PM   #5
M1KE
Senior Member
 
Join Date: Feb 2009
Posts: 143
Default

How do you do that. How does the computer know which key. I looked into it and it got me puzzled
M1KE is offline   Reply With Quote
Old 02-20-2009, 04:02 PM   #6
PhatKitty
Registered User
 
Join Date: Jan 2009
Posts: 30
Default

How do I do what? And lemme try and fix the problem.
PhatKitty is offline   Reply With Quote
Old 02-20-2009, 04:05 PM   #7
PhatKitty
Registered User
 
Join Date: Jan 2009
Posts: 30
Default

Try:

ActionScript Code:
var Paused:Boolean = false if (Key.isDown(80)) { Paused = true; } if (Paused == true && (Key.isDown(80))) { Paused = false; } if (Key.isDown(80)) { then the rest of the monster = false stuff
PhatKitty is offline   Reply With Quote
Old 02-20-2009, 04:34 PM   #8
M1KE
Senior Member
 
Join Date: Feb 2009
Posts: 143
Default

KeyListener = new Object();
KeyListener.onKeyDown = function() {
var KeyCode = Key.getCode();
if (KeyCode == 80) {
if (Paused) {
var Paused:Boolean = false;
} else {
var Paused:Boolean = true;
}
}
Thats what I tried but it doesn't even recognise that 'p' is being pressed I checked it with a trace command
M1KE is offline   Reply With Quote
Old 02-20-2009, 04:40 PM   #9
PhatKitty
Registered User
 
Join Date: Jan 2009
Posts: 30
Default

I think you have to state the variables at the top of the script, then after that you only need to put Paused = false/true:

var Paused:Boolean = false;

KeyListener = new Object();
KeyListener.onKeyDown = function() {
var KeyCode = Key.getCode();
if (KeyCode == 80) {
if (Paused) {
Paused = false;
} else {
Paused = true;
}
}
PhatKitty is offline   Reply With Quote
Old 02-20-2009, 04:45 PM   #10
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

Maybe I should have said onKeyUp ? It's been a long time since I used as2 so I sometimes forget these things.
rrh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS2] Game pausing and movie clips playing/stopping. factory Gaming and Game Development 3 02-17-2009 01:45 PM
[AS2] flash game and audio un sync ultraman Gaming and Game Development 0 08-05-2008 06:35 PM
FlashGameLicense.com - virtual marketplace to connect game developers and buyers AdamSchroeder General Chat 0 12-18-2007 09:16 PM
[AS2] Tile game or not tile game? krolben Gaming and Game Development 4 07-28-2004 12:41 PM
[AS2] Locating bug in game MiniMurderdoll Gaming and Game Development 0 06-01-2004 10:27 AM


All times are GMT. The time now is 09:56 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.