简体   繁体   English

gamequery碰撞检测不反应

[英]gamequery collision detection doesnt react

i created 2 sprite objects and want to check if they collide, but it doesnt seem to work. 我创建了2个Sprite对象,并想检查它们是否发生碰撞,但似乎不起作用。

My code: 我的代码:

creation of the sprites:** 精灵的创建:**

.addGroup("flying", {width: 366, height: 254})

.addSprite("flyinganimation",{animation: flight, 
                  posx: 0, posy: 0, width: 366, height: 254})

.addGroup("obstacles",  {width: 169, height: 67})

.addSprite("obstaclenames", {animation: obstacleimage,
            width: 169,height: 67,
            posx: 300,
            posy: 400})

looped code in the callback function:** 回调函数中的循环代码:**

var collision = $("#flying,.group").collision("#obstacles,.group");

if (collision > 0)
{
 document.write ("collision");
} 

I see two potential problems here: 1) collision() returns a jQuery object so you will need to do a .size() in order to retrieve the number of collisions 2) you should apply collision() to only one object. 我在这里看到了两个潜在的问题:1)crash()返回一个jQuery对象,因此您需要执行.size()才能检索到冲突的次数2)您应该仅将碰撞()应用到一个对象。

To sum up your first line should look like this: 总结一下第一行应该是这样的:

var collision = $("#flying").collision("#obstacles,.group").size();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM