/** * Call this function to see if one <code>FlxObject</code> collides with another. * Can be called with one object and one group, or two groups, or two objects, * whatever floats your boat! It will put everything into a quad tree and then * check for collisions. For maximum performance try bundling a lot of objects * together using a <code>FlxGroup</code> (even bundling groups together!) * NOTE: does NOT take objects' scrollfactor into account. * * @param Object1 The first object or group you want to check. * @param Object2 The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group. */ public static bool collide(FlxObject Object1, FlxObject Object2) { if( (Object1 == null) || !Object1.exists || (Object2 == null) || !Object2.exists ) return false; quadTree = new FlxQuadTree(FlxQuadTree.bounds.x,FlxQuadTree.bounds.y,FlxQuadTree.bounds.width,FlxQuadTree.bounds.height,null); quadTree.add(Object1,FlxQuadTree.A_LIST); bool match = Object1 == Object2; if(!match) quadTree.add(Object2,FlxQuadTree.B_LIST); bool cx = quadTree.overlap(!match,solveXCollision); bool cy = quadTree.overlap(!match,solveYCollision); return cx || cy; }
/** * Call this function to see if one <code>FlxObject</code> overlaps another. * Can be called with one object and one group, or two groups, or two objects, * whatever floats your boat! It will put everything into a quad tree and then * check for overlaps. For maximum performance try bundling a lot of objects * together using a <code>FlxGroup</code> (even bundling groups together!) * NOTE: does NOT take objects' scrollfactor into account. * * @param Object1 The first object or group you want to check. * @param Object2 The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group. * @param Callback A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject);</code> If no function is provided, <code>FlxQuadTree</code> will call <code>kill()</code> on both objects. */ static public bool overlap(FlxObject Object1, FlxObject Object2, SpriteCollisionEvent Callback) { if ((Object1 == null) || !Object1.exists || (Object2 == null) || !Object2.exists) { return(false); } quadTree = new FlxQuadTree(FlxQuadTree.bounds.x, FlxQuadTree.bounds.y, FlxQuadTree.bounds.width, FlxQuadTree.bounds.height, null); quadTree.add(Object1, FlxQuadTree.A_LIST); if (Object1 == Object2) { return(quadTree.overlap(false, Callback)); } quadTree.add(Object2, FlxQuadTree.B_LIST); return(quadTree.overlap(true, Callback)); }
/** * Call this function to see if one <code>FlxObject</code> collides with another. * Can be called with one object and one group, or two groups, or two objects, * whatever floats your boat! It will put everything into a quad tree and then * check for collisions. For maximum performance try bundling a lot of objects * together using a <code>FlxGroup</code> (even bundling groups together!) * NOTE: does NOT take objects' scrollfactor into account. * * @param Object1 The first object or group you want to check. * @param Object2 The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group. */ static public bool collide(FlxObject Object1, FlxObject Object2) { if ((Object1 == null) || !Object1.exists || (Object2 == null) || !Object2.exists) { return(false); } quadTree = new FlxQuadTree(FlxQuadTree.bounds.x, FlxQuadTree.bounds.y, FlxQuadTree.bounds.width, FlxQuadTree.bounds.height, null); quadTree.add(Object1, FlxQuadTree.A_LIST); bool match = Object1 == Object2; if (!match) { quadTree.add(Object2, FlxQuadTree.B_LIST); } bool cx = quadTree.overlap(!match, solveXCollision); bool cy = quadTree.overlap(!match, solveYCollision); return(cx || cy); }
/** * Call this function to see if one <code>FlxObject</code> overlaps another. * Can be called with one object and one group, or two groups, or two objects, * whatever floats your boat! It will put everything into a quad tree and then * check for overlaps. For maximum performance try bundling a lot of objects * together using a <code>FlxGroup</code> (even bundling groups together!) * NOTE: does NOT take objects' scrollfactor into account. * * @param Object1 The first object or group you want to check. * @param Object2 The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group. * @param Callback A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject);</code> If no function is provided, <code>FlxQuadTree</code> will call <code>kill()</code> on both objects. */ public static bool overlap(FlxObject Object1, FlxObject Object2, SpriteCollisionEvent Callback) { if( (Object1 == null) || !Object1.exists || (Object2 == null) || !Object2.exists ) return false; quadTree = new FlxQuadTree(FlxQuadTree.bounds.x,FlxQuadTree.bounds.y,FlxQuadTree.bounds.width,FlxQuadTree.bounds.height, null); quadTree.add(Object1,FlxQuadTree.A_LIST); if(Object1 == Object2) return quadTree.overlap(false,Callback); quadTree.add(Object2,FlxQuadTree.B_LIST); return quadTree.overlap(true,Callback); }