簡體   English   中英

GameQuery碰撞檢測無法正常工作

[英]GameQuery collision detection not working properly

下面是我的代碼。 碰撞實際上會注冊並執行,但前提是您的飛船在屏幕的右邊緣,並且其中有一個怪物在您后面。 這沒有任何意義,我要瘋了。 請幫忙。

演示: http : //cosmati.net/biebsattack/test2.html它輸出游戲區域下方的任何碰撞,包括導彈和敵人的坐標。 此外,請隨意笑,這只是帶有一些附加風味和裝飾的gamequery教程。 ;) 編輯 :另外,我知道資產非常龐大。 僅用於測試。 很抱歉加載時間。

        $.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);

我只是發現這是因為我使用更新CSS的棄用方法(selector.css(“ left”,posx);)而不是新方法(selector.x)來設置x,y坐標。

現在工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM