繁体   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