下面是我的密码。碰撞实际上注册和执行,但只有当你的船在屏幕的右边边缘,其中一个怪物在你身后。这没道理,我要疯了。请帮帮忙。
演示: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);发布于 2012-05-21 04:25:26
我刚刚发现这是因为我使用的是更新CSS (selector.css(“左”,posx))而不是新方法(selector.x)来设置x,y坐标。
现在正常工作了。
https://stackoverflow.com/questions/10677983
复制相似问题