0

以下は私のコードです。衝突は実際に登録されて実行されますが、それはあなたの船が画面の右端にあり、モンスターの 1 人があなたの後ろにいる場合に限られます。意味が分からなくて気が狂いそう。助けてください。

デモ: 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);
4

1 に答える 1

0

新しい方法 (selector.x) ではなく、CSS を更新する非推奨の方法 (selector.css("left",posx);) を使用して x、y 座標を設定していたためだとわかりました。

現在、正常に動作しています。

于 2012-05-21T04:25:26.837 に答える