Reputation: 494
I'm trying to handle the collisions on a game with collision() but I don't understand what's going on. 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)?
Thanks.
PS: "sp_viseur" added to the playground like the other sprites.
Upvotes: 0
Views: 187
Reputation: 320
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'). Gamequery uses the posx and posy properties but if you use the .x() and .y() functions they should be synchronized.
Upvotes: 1