The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.39 / 5.00 38,635 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 15,161 ViewsHey everyone..!
Just reworking the pause menu in my game I'm developing. Here's a dumbed down version of the code I'm using and exactly what my problem is:
http://pastebin.com/m728db5c3
Thanks a bunch,
~Guil
if (Key.isDown(80)) {
if (MenuSS == false) {
MenuSS = true;
} else {
MenuSS = false;
}
}
//try adding an if keyup function here, dunno how it goes to be honest...
if(keyUp == true){
if (MenuSS == true) {
//Make the menu appear..
} else {
//Make the menu disappear..
}
}
There's my problem.
There is no Key.isUp..
I used to use .isToggled - however Flash Player would sometimes start with .isToggled = true and sometimes it would be false; depending on if you had pressed it before making Flash Player the focus of a browser..
~Guil
I've been suggested this a couple times:
if (Key.isDown(80) && !pressed) {
pressed = true;
if (MenuSS == true) {
MenuSS = false;
} else {
MenuSS = true;
}
} else {
pressed = false;
}
However the same thing happens..
i had this problem, its easy, set a timer variable to say like 50 when the button is pressed.
in your main code simply check if its above 0 and if it is subtract one per frame.
when checking if the button is pressed also check if that variable is above 0, if its 0 alow the button to register and bring up or bring down the pause menu.
hope this makes sense. but ive used it before lots.
if (Key.isDown(80) && Menutimer == 0) {
Menutimer = 50;
if (MenuSS == false) {
MenuSS = true;
} else {
MenuSS = false;
}
}
if(Menutimer > 0) {
Menutimer--;
}
if (MenuSS == true) {
//Make the menu appear..
} else {
//Make the menu disappear..
} Thanks, I was considering a timer.. Maybe it's simpler.
Using Key.isToggled was perfect except that you can't set whether or not the key is toggled to true or false at the beginning of playback..
I decided to change it because sometimes when you first click into the Flash Player and thus put it in focus, sometimes Key.isToggled would be true - and sometimes false.. So I'd end up with the pause menu jumping up the instant you click into the game.
~Guil
For cases where you want to test whether a key is up or down, you just need to test if the key is down.
Key.isDown(80) works as a true/false variable. Putting '== false' afterwards (or an exclamation mark beforehand, however you want to do it) runs the code if it ISN'T down.
However, don't bother with that this time, because you just need an 'else' statement.
Call it background reading
if (Key.isDown(80)) {
if (keyheld == false) {
// checks a variable called 'keyheld', and only runs the code if it is false
keyheld = true;
// changes keyheld to true, meaning the code does not repeat until it is changed back
if (MenuSS == false) {
MenuSS = true;
} else {
MenuSS = false;
}
}
} else {
// i.e. if the key is NOT down
keyheld = false;
// changes keyheld back to false
}
So, when the key is first pressed, it changes a variable to say 'true'. Then, if it is held, it doesn't run the code again, because that variable is 'true', and it has been told not to run the code if it is true.
When the key isn't down, it changes that variable to 'false', meaning the next key press makes the code run again.
This differs from your new 'suggestion', because your suggestion has a small problem.
The 'else' block of code runs if the key is not down, OR your variable is 'true'. So it keeps changing the variable back to false whenever it is true.
Doomsday-One, working on stuff better than preloaders. Marginally.
That's brilliant, Doomsday-One!
Works like a charm, thank you; I really appreciate it.
Simple explanation with example, thanks again..!
~Guil