以下は私のコードです。衝突は実際に登録されて実行されますが、それはあなたの船が画面の右端にあり、モンスターの 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);