thunderfight20xx missle lockup
  • Has anyone experienced the missle locking up on Thunderfight20xx if you press the k button rapidly.  Any advice on how to avoid that?

    Thanks

     

  • selimselim
    Accepted Answer
    Yes it's a known bug. It has to do with the way the name of the missile sprite is generated. The name is made of a prefix followed by a random number. On some occasion, when there are a lot of missiles on screen, there is a chance for this name not to be unique.

    Since the name it the id of the DOM element this causes this bug. The solution is to use a reasonably large enough counter instead of the random number. The counter will reset to 0 after it reaches some point.

  • Good call!

    Here is the counter fix I put in. I think it works!



    /*ASSOCIATE KEYDOWN WITH FIRING MISSILES*/
    var IDCount = 0;
    $(document).keydown(function(e){
    //if(!gamestate.gameOver && !gamestate.playerHit){
    switch(e.keyCode){
    case 75: //this is shoot (k)
    var playerposx = $("#player").x();
    var playerposy = $("#player").y();
    //var name = "playerMissle_"+Math.ceil(Math.random()*1000);
    var name = "playerMissle_"+IDCount++;
    $("#grouppmissile").addSprite(name,{animation: missile.player, posx: playerposx + 90, posy: playerposy + 14, width: 36,height: 10});
    $("#"+name).addClass("playerMissiles");
    console.log($("#"+name));
    break;
    }
    //}
    });


    Thanks for that tip

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!