首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GameQuery碰撞检测不正常

GameQuery碰撞检测不正常
EN

Stack Overflow用户
提问于 2012-05-20 23:09:02
回答 1查看 346关注 0票数 0

下面是我的密码。碰撞实际上注册和执行,但只有当你的船在屏幕的右边边缘,其中一个怪物在你身后。这没道理,我要疯了。请帮帮忙。

演示:http://cosmati.net/biebsattack/test2.html它输出游戏区域以下的任何碰撞,包括导弹和敌人的坐标。此外,请随意笑,这只是一个游戏查询教程,添加了一些风味和装饰。编辑:而且,我知道,这些资产是巨大的。只是为了测试。很抱歉装载时间到了。

代码语言:javascript
复制
        $.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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-21 04:25:26

我刚刚发现这是因为我使用的是更新CSS (selector.css(“左”,posx))而不是新方法(selector.x)来设置x,y坐标。

现在正常工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10677983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档