简体   繁体   English

Gamequery 碰撞的奇怪行为 function

[英]Strange behaviour with Gamequery's collision function

I'm trying to handle the collisions on a game with collision() but I don't understand what's going on.我正在尝试使用collision()处理游戏中的碰撞,但我不明白发生了什么。 Here's a summary:这是一个总结:

    $("#screen").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH});
$.playground().addSprite("wall",{animation:anim_mur, posx: 0, posy: -100, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT+300})
    .addSprite("table",{animation:anim_tableau, posx: 459, posy: 122, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$.playground().addGroup('enemies', {width: 320, height: 280}).end()
            .addSprite("sp_bed",{animation:anim_bed, posx: PLAYGROUND_WIDTH-400, posy: 210, width: 320, height: 280})

And then I handle the collisions there然后我处理那里的碰撞

$("#sp_viseur").collision("#enemies").each(function(){
    alert('test');
    });

And I fill the "enemies" group with sprites in another function. I want the function to be called any time the "sp_viseur' sprite collides with a sprite of the "enemies" group. But the function is never called: I ran a few more tests so I have question? how does the "collision" function work, Does it use the css attributes (left. top..,) or the gamequery ones (posx?posy)?我在另一个 function 中用精灵填充“敌人”组。我希望在“sp_viseur”精灵与“敌人”组的精灵碰撞时调用 function。但是 function 从未被调用:我跑了一些更多测试,所以我有问题?“碰撞”function 是如何工作的,它使用 css 属性(左上..,)还是 gamequery 属性(posx?posy)?

Thanks.谢谢。

PS: "sp_viseur" added to the playground like the other sprites. PS:“sp_viseur”像其他精灵一样添加到操场上。

Sorry I realized that my answer wasn't exactly what you asked for:抱歉,我意识到我的回答并不完全符合您的要求:

.collision() don't return collision with groups so you have to add to the.collision selector a class that will be applied to all your enemies sprites for example.collision('#enemies,.enemies'). .collision() 不会返回与组的碰撞,因此您必须向 .collision 选择器添加一个 class,它将应用于您所有的敌人精灵,例如 example.collision('#enemies,.enemies')。 Gamequery uses the posx and posy properties but if you use the.x() and.y() functions they should be synchronized. Gamequery 使用 posx 和 posy 属性,但如果您使用 .x() 和 .y() 函数,则它们应该同步。

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

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