0

my jsfiddle:http://jsfiddle.net/Qfe6L/2/

 $(window).keypress(function (e) {
            if (e.which == 32) {
                CreateChuriken();
                $(".Shuriken").animate({ left: '+=300px' }, 'slow');
            }
        });

as you can see if you hit on start button and keep on pressing space in a fast way the counter act weird and the amount of enemies created start to be massive the game enter an infinite loop somewhere but i can't find where can anyone help me please

14
  • 2
    sorry can't replicate. can you be more exact on how to reproduce the bug? Commented Jul 24, 2013 at 13:19
  • It seems to work fine. I'm using Chrome. Which browser (+version) are you using? Commented Jul 24, 2013 at 13:19
  • please try hitting on space button when moving the player up and down and see what is happening Commented Jul 24, 2013 at 13:21
  • 2
    ok, how do you move it up and down? arrows not working for me? :) Commented Jul 24, 2013 at 13:22
  • what do u mean arrow is not working they should definitely work you can move it using the up arrow and the down arrow key Commented Jul 24, 2013 at 13:23

2 Answers 2

1

Each time the start button is clicked, you are creating a new timeout, which sets up a 60 second window of spawning enemies and increments the counter. As it has been stated, when you press space to attack, that can also press the start button if the button has focus.

Disable the button when you start things:

    $("#Start").click(function () {
        $('#Start').attr('disabled', 'disabled');

        startTimer();
        ReleaseEnemies()
    });

This will avoid what effectively is running multiple 'copies' of your game logic.

Sign up to request clarification or add additional context in comments.

Comments

0

If you press space while a button has focus, the browser counts it as a click.
In my experience multiple hits to the start button cause the problem you described.
Try to eliminate further clicks after the initial (disable it, maybe).

1 Comment

Good catch. I can verify that multi-clicking the start button makes things act funny (in particular, generating a lot more enemies

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.