0

i created 2 sprite objects and want to check if they collide, but it doesnt seem to work.

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");
} 

1 Answers1

1

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.

To sum up your first line should look like this:

var collision = $("#flying").collision("#obstacles,.group").size();
Selim Arsever
  • 320
  • 1
  • 6