2012-05-20 43 views
0

下面是我的代碼。碰撞實際上是註冊和執行的,但只有當你的船在屏幕的右邊緣,並且其中一個怪物在你身後。這沒有意義,我會發瘋。請幫忙。GameQuery碰撞檢測不正常

演示:http://cosmati.net/biebsattack/test2.html 它輸出任何在玩區域下面的碰撞,包括導彈和敵人的座標。此外,隨時可以笑,這只是一些添加味道和裝飾的遊戲教程。 ;)編輯:此外,資產是巨大的,我知道。只是爲了測試。抱歉關於加載時間。

 $.playground().registerCallback(function() { 

      $(".playerMissiles").each(function() { 
       //Test for collisions 
       var collided = $(this).collision(".enemy,#enemies"); 
       if (collided.length > 0) { 
        var missilenum = $(this).attr("id"); 
        var missilecoords = $(this).css("left") + ", " + $(this).css("top"); 
        //An enemy has been hit! 
        collided.each(function() { 
         $("#lblCollisionLog").append(missilenum + " (" + missilecoords + ") collided with " + $(this).attr("id") + " (" + $(this).css("left") + ", " + $(this).css("top") + ") <br>"); 
         if ($(this)[0].enemy.damage()) { 
          $(this).setAnimation(enemies[0]["explode"], function (node) { $(node).remove(); }); 
          $(this).css("width", 99); 
          $(this).removeClass("enemy"); 
         } 
        }) 
        $(this).setAnimation(missile["playerexplode"], function (node) { $(node).remove(); }); 
        $(this).css("width", 99); 
        $(this).css("height", 99); 
        $(this).css("top", parseInt($(this).css("top")) - 7); 
        $(this).removeClass("playerMissiles"); 
       } 

      }); 
     }, 10); 

回答

0

我剛剛發現這是因爲我設置x,y座標使用更新CSS的方法已過時(selector.css(「左」,POSX);)而不是新的方法(選擇。 X)。

現在工作正常。