Jump to content

Problem with key.isdown and overlap


smdu57
 Share

Recommended Posts

Hello

I have a problem. I want my player when he is in front of a bottle and when he interract with it (up arrow key) the frame of the bottle change.

The problem is I use an overlap between player and bottle I use :

if (cursors.up.isDown)
    {
    	bouteille.frame = bouteille.frame +1;
    }

but when in game I press the up key it change all frame in one ms. How can I set a timer or something to say I pressed one time I need to release key and do it only after repressed 

Thanks

Link to comment
Share on other sites

Well I found something interesting, if I use an alert just like that :

if (cursors.up.isDown && points > 0)
    {
    	alert();
    	bouteille.frame = bouteille.frame +1;
    }

It make exactly what I want, a break between two pressed key. The problem is there is a popup and you should close it before continuing the game. So is there any way to make an alert without popup or just a kind of break or sleep in program ?

Link to comment
Share on other sites

I figured out myself I just added a variable in the if statement, this variable is set to 1 then the function inside the if set it to 0 and I added a eventListener onUp that change this var to 1 and it worked

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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