How to have a function fire when collision & returns occur
I've been messing around with jQuery Collision for some time now but still cannot figure out how to make use of it in a simple way, despite having examples to try to help.
http://sourceforge.net/p/jquerycollision/wiki/Home/#usage says this:
- Basic usage returns the obstacles that are hit by the colliders:
-
var colliders_selector = ".collider";
-
var obstacles_selector = ".obstacle";
-
var hits = $(colliders_selector).collision(obstacles_selector)
How can I craft a statement that has a function fire when var hits
notices that a collision has occurred? I tried doing this:
- var colliders_selector = $(links[i]);
- var obstacles_selector = ".footer";
- var hits = $(colliders_selector).collision(obstacles_selector)
-
- if (hits) {
- alert("d");
- }
But the alerts occur even before a collision does, so I assume the if statement is just noting that hits exists 4 times.
I also tried this because it is similar to an example's code:
- var colliders_selector = $(links[i]);
var obstacles_selector = ".footer";
var hits = $(colliders_selector).collision(obstacles_selector)
- for (var i=0; i<hits.length; i++) {
}
But the for loop caused the browser to freeze so obviously I'm doing something wrong there, too.
So I'm rather at a loss for what to do. Help would be appreciated.