Jump to content

Implementing a delay in a title screen


aklaino
 Share

Recommended Posts

Hello again, now I'm messing around with a title screen system. Unfortunately, it seems to cycle too fast when I press the down or up buttons so I tried implementing the timer object in it and I'm trying to delay the game slightly. Any suggestions?

Here's the code for my cursor class (except for the last function for some reason):

else if(game.input.keyboard.isDown(Phaser.Keyboard.UP)){				var timer = new Phaser.Timer(game, true);								if(l > 0)					l--;				else					l = coords.length - 1;				cursor.destroy();				controls.pop();				createCursor(l);				timer.start(500);			}						// Move down			else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)){				var timer = new Phaser.Timer(game, true);								if(l < coords.length - 1)					l++;				else					l = 0;				cursor.destroy();				controls.pop();				createCursor(l);				timer.start(500);							}		}
Link to comment
Share on other sites

Use a flag to check if up/down action should be allowed, and set the flag once the action taken, reset the flag once the action is done. Something like this:

if (allowAction && isDown(UP)) {  allowAction = false;  doAction();}doAction = function() {  // reset the flag once the action is finished, this could be a callback of some sort. eg: like this  action.onActionDone = function() {    allowAction = true;  };}
Link to comment
Share on other sites

I think you're trying to make a cursor controlled menu and the problem is that it moves too quickly...?

There are several solutions to this problem:

1. record the game.time.now value when the cursor moves, don't permit another move until game.time.now > lastMoveTime + 500 (half a second delay)

2. prevent auto-repeat on the keyboard by detecting the keydown event, or wait a day or two, grab the dev branch, and use the brand new 'justDown' variable which is only true when the key has been released and pressed again since the last time you checked.  (Player can tap the up/down keys to move quickly).  This is a built-in version of what eguneys suggested.

3. use the timer like you were trying, but check to see if it has finished before you check if the key is pressed, if it hasn't finished you should ignore the keypress

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...