Author Topic: Overriding Pause  (Read 993 times)

superbany

  • Member
  • **
  • Posts: 53
  • Karma: +0/-0
  • [Please enter text here]
    • View Profile
    • Superbany's games
Overriding Pause
« on: Tue, Jul 12, 2011 »
I'm trying to override the default Flixel pause (with flixel v2.35), so I went and made my own PauseMenu class and set it up in my game.
The player can either press P to pause, or click a button on the screen to  call the togglePause() function in my game state. The button works fine, but for some reason, the P key has to be held down instead of pressed once to pause. Also, neither one show the test image I put in the pause menu, but it is shown when focus is lost in the main menu before playState is loaded. Any ideas?

PauseMenu:
Code: [Select]
public class PauseMenu extends FlxGroup
{

public function PauseMenu()
{
var testSprite:FlxSprite;
super();
scrollFactor.x = scrollFactor.y = 0;
testSprite = new FlxSprite(64, 64);
testSprite.createGraphic(16, 16);
add(testSprite);
reset(0, 0);
}

override public function update():void
{
FlxG.log("inpause");
if (FlxG.keys.justPressed("P"))
FlxG.pause = !FlxG.pause;
super.update();
}

}

PlayState:
Code: [Select]
override public function create():void
{
tempSprite = new FlxSprite(0, 0, ImgButtonPause);
_buttonPause = new FlxButton(FlxG.width - 10, FlxG.height - 9,togglePause);
_buttonPause.loadGraphic(tempSprite);
_buttonPause.scrollFactor.x = _buttonPause.scrollFactor.y = 0;
_hud.add(_buttonPause);
}

override public function update():void
{
FlxG.log("1:" + FlxG.pause);
if (FlxG.keys.justPressed("P"))
togglePause();
FlxG.log("2:" + FlxG.pause);
super.update();
}

protected function togglePause():void
{
FlxG.pause = !FlxG.pause;
}

For the log in playState's update, 1 is always returning false, and 2 is only true for a single frame once P is pressed.

Any help with what is happening here would be great. Thanks!

zadvornykh

  • Active Member
  • ***
  • Posts: 205
  • Karma: +1/-0
    • View Profile
Re: Overriding Pause
« Reply #1 on: Tue, Jul 12, 2011 »
You should not need to have the justPressed check both in the pause menu and in the playstate. In fact, this may well cause the pause flag to be flipped twice every frame.

superbany

  • Member
  • **
  • Posts: 53
  • Karma: +0/-0
  • [Please enter text here]
    • View Profile
    • Superbany's games
Re: Overriding Pause
« Reply #2 on: Wed, Jul 13, 2011 »
I tried having only one before, and that caused problems too; removing the key command from playState pauses the game correctly when p is pressed, but then the game stays paused and the p key has to be held down to continue playing. Removing justPressed from the pause menu changes nothing.