It's important to make sure the elements were created using the .addSprite()
function and also have to be moved around using gamequeryjs
functions.
I would also just use alert('Collision!');
without an if/else just to see what happens.
题
I'm using gamequery http://gamequeryjs.com/ for a very simple game I'm building. I'm trying to use the collision function to determine when two divs have collided, these divs would be styled to display sprite animations. Here's an example of the collision function:
$(“#spaceship”).collision(“.missiles”).each(function(){
killspaceship();
explodemissil(this);
});
More information on the collision function can be found here:http://gamequeryjs.com/documentation/api/#collision
Now here's my code:
var collided = $("#sprite1").collision("#sprite2");
if(collided.length > 0){
alert('Collision!');
}
and it's not working. Would appreciate help knowing what I'm doing wrong or if you have another solution for collision detection in jquery or js.
解决方案
It's important to make sure the elements were created using the .addSprite()
function and also have to be moved around using gamequeryjs
functions.
I would also just use alert('Collision!');
without an if/else just to see what happens.