CCCollision
CCCollision
Cocos2DStatic utility class for common 2D collision detection operations. Built on top of CCRect.IntersectsRect() and CCRect.ContainsPoint().
Inheritance: System.Object
Methods
CheckCollisionsFiltered(CCNode, IList, float, Action)
CheckCollisionsFiltered(CCNode, IList, float, Action)(Cocos2D.CCNode single, System.Collections.Generic.IListT group, System.Single shrink, System.ActionCocos2D.CCNode,T onCollision)Checks a single node against a list of nodes for collisions, respecting CollisionCategory/CollisionCategoryMask filtering. Only tests pairs where ShouldCollide returns true.
Parameters:
single (Cocos2D.CCNode)group (System.Collections.Generic.IListT)shrink (System.Single)onCollision (System.ActionCocos2D.CCNode,T)Example
CheckCollisions(CCNode, IList, float, Action)
CheckCollisions(CCNode, IList, float, Action)(Cocos2D.CCNode single, System.Collections.Generic.IListT group, System.Single shrink, System.ActionCocos2D.CCNode,T onCollision)Checks a single node against a list of nodes for collisions. Calls the handler for each collision found.
Parameters:
single (Cocos2D.CCNode)group (System.Collections.Generic.IListT)shrink (System.Single)onCollision (System.ActionCocos2D.CCNode,T)Example
CheckGroupCollisionsFiltered(IList, IList, float, Action)
CheckGroupCollisionsFiltered(IList, IList, float, Action)(System.Collections.Generic.IListTA groupA, System.Collections.Generic.IListTB groupB, System.Single shrink, System.ActionTA,TB onCollision)Checks two groups of nodes against each other for collisions, respecting CollisionCategory/CollisionCategoryMask filtering. Only tests pairs where ShouldCollide returns true.
Parameters:
groupA (System.Collections.Generic.IListTA)groupB (System.Collections.Generic.IListTB)shrink (System.Single)onCollision (System.ActionTA,TB)Example
CheckGroupCollisions(IList, IList, float, Action)
CheckGroupCollisions(IList, IList, float, Action)(System.Collections.Generic.IListTA groupA, System.Collections.Generic.IListTB groupB, System.Single shrink, System.ActionTA,TB onCollision)Checks two groups of nodes against each other for collisions. Calls the handler for each collision found.
Parameters:
groupA (System.Collections.Generic.IListTA)groupB (System.Collections.Generic.IListTB)shrink (System.Single)onCollision (System.ActionTA,TB)Example
ContainsPoint(CCNode, CCPoint, float)
System.Boolean ContainsPoint(CCNode, CCPoint, float)(Cocos2D.CCNode node, Cocos2D.CCPoint point, System.Single shrink)Checks whether a point is within a node's bounding box (with optional shrink).
Parameters:
node (Cocos2D.CCNode)point (Cocos2D.CCPoint)shrink (System.Single)Returns:
System.BooleanExample
GetShrunkBounds(CCNode, float)
Cocos2D.CCRect GetShrunkBounds(CCNode, float)(Cocos2D.CCNode node, System.Single shrinkFactor)Returns a node's bounding box shrunk by the given factor. A factor of 1.0 returns the full bounding box. A factor of 0.5 returns a box that is 50% the original size, centered.
Parameters:
node (Cocos2D.CCNode)shrinkFactor (System.Single)Returns:
Cocos2D.CCRectExample
Overlaps(CCNode, CCNode, float)
System.Boolean Overlaps(CCNode, CCNode, float)(Cocos2D.CCNode a, Cocos2D.CCNode b, System.Single shrink)Checks whether two nodes' bounding boxes overlap, with an optional shrink factor. A shrink of 1.0 uses full bounding box, 0.5 uses half-size, etc.
Parameters:
a (Cocos2D.CCNode)b (Cocos2D.CCNode)shrink (System.Single)Returns:
System.BooleanExample
Overlaps(CCRect, CCRect)
System.Boolean Overlaps(CCRect, CCRect)(Cocos2D.CCRect a, Cocos2D.CCRect b)Checks whether two rectangles overlap (AABB intersection test).
Parameters:
a (Cocos2D.CCRect)b (Cocos2D.CCRect)Returns:
System.BooleanExample
ShouldCollide(CCNode, CCNode)
System.Boolean ShouldCollide(CCNode, CCNode)(Cocos2D.CCNode a, Cocos2D.CCNode b)Checks whether two nodes should test for collision based on their CollisionCategory and CollisionCategoryMask bitmasks. Returns true only if both nodes' categories match the other's mask (bilateral).
Parameters:
a (Cocos2D.CCNode)b (Cocos2D.CCNode)Returns:
System.BooleanExample