Sign in to follow this  
smdu57

Problem with key.isdown and overlap

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

Share this post


Link to post
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 ?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.