0

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.

2
  • have you tried debugging collided to see what's in it? Commented Mar 4, 2014 at 3:01
  • Can we get a jsFiddle with a simple demonstration illustrating this fact please Commented Mar 4, 2014 at 3:15

1 Answer 1

1

It's important to make sure the elements were created using the .addSprite() function and also have to be moved around using gamequeryjs functions.

http://vimeo.com/64073558

I would also just use alert('Collision!'); without an if/else just to see what happens.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.