<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Tag: collision - Recent Posts</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/collision</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 03:32:43 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/tags/collision" rel="self" type="application/rss+xml" />

		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/4#post-143386</link>
			<pubDate>Thu, 09 Feb 2012 03:04:36 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">143386@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks Dani - I didn't change very much of your code :) - I just dynamically created the render texture, and matched its size to that of the intersection rectangle. </p>
<p>After fixing the error in calculating the offset, my fps is just ~50fps on a first gen iPhone when the bounding boxes constantly overlap.<br />
The fps should be better on 3gs - I don't have one so I can't check. On 4th Gen iPod it is 60 (for checks every frame when bounding boxes overlap). </p>
<p>On older devices this test is probably ideal for projectiles, or objects which will stop checking after one positive instance of collision, or in cases where bounding boxes won't overlap for too many consecutive frames. I'm not aware of any other technique which is more efficient or easier to use for sprites of irregular shapes and orientations.
</p></description>
		</item>
		<item>
			<title>Dani on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/4#post-143248</link>
			<pubDate>Wed, 08 Feb 2012 10:57:49 +0000</pubDate>
			<dc:creator>Dani</dc:creator>
			<guid isPermaLink="false">143248@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p><strong>@SomeGuy</strong>: It's a common error, I have make millions of mistakes with offsets, and in general, false positives are caused by them. By the way, very good improvements, congratulations!
</p></description>
		</item>
		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/4#post-143218</link>
			<pubDate>Wed, 08 Feb 2012 07:03:19 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">143218@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I figured it out - it was due to an error on my part in calculating the offset. Sorry about the confusion.
</p></description>
		</item>
		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-142742</link>
			<pubDate>Sun, 05 Feb 2012 13:20:21 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">142742@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>After more testing - I have found some false positives &#38; false negatives using this algorithm.<br />
For example, sometimes a collision is detected even when two sprites are close to each other but not touching.</p>
<p>No collision:<br />
<img src="http://img210.imageshack.us/img210/2417/nocollision.png" alt="Image Hosted by ImageShack.us" /></p>
<p>False collision:<br />
<img src="http://img846.imageshack.us/img846/1409/collision.png" alt="Image Hosted by ImageShack.us" /></p>
<p>What could be wrong? :(<br />
Here is my code:<br />
<pre><code>-(BOOL) isCollisionBetweenSpriteA:(CCSprite*)spr1 spriteB:(CCSprite*)spr2 pixelPerfect:(BOOL)pp
{
    BOOL isCollision = NO; 

    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init];
    CGRect intersection = CGRectIntersection([spr1 boundingBox], [spr2 boundingBox]);

    // Look for simple bounding box collision
    if (!CGRectIsEmpty(intersection))
    {
        // If we&#039;re not checking for pixel perfect collisions, return true
        if (!pp) {return YES;}

        CGPoint spr1OldPosition = spr1.position;
        CGPoint spr2OldPosition = spr2.position;

        [self offsetX:spr1 intersection:intersection];
        [self offsetY:spr1 intersection:intersection];

        [self offsetX:spr2 intersection:intersection];
        [self offsetY:spr2 intersection:intersection];

        intersection = CGRectIntersection([spr1 boundingBox], [spr2 boundingBox]);

        // Offset
        CCSpriteBatchNode* _sbnMain =(CCSpriteBatchNode*) spr1.parent;

        //NOTE: We are assuming that the spritebatchnode is always at 0,0
        //        CGPoint oldBatchPosition = _sbnMain.position;        

        // Get intersection info
        unsigned int x = (intersection.origin.x)* CC_CONTENT_SCALE_FACTOR();
        unsigned int y = (intersection.origin.y)* CC_CONTENT_SCALE_FACTOR();
        unsigned int w = intersection.size.width* CC_CONTENT_SCALE_FACTOR();
        unsigned int h = intersection.size.height* CC_CONTENT_SCALE_FACTOR();
        unsigned int numPixels = w * h;// * CC_CONTENT_SCALE_FACTOR();

        // create render texture and make it visible for testing purposes
        int renderWidth = w;
        int renderHeight = h;

        if(renderWidth&#60;16)
        {
            renderWidth = 16;
        }

        if(renderHeight &#60; 16)
        {
            renderHeight = 16;
        }

        CCRenderTexture* _rt = [CCRenderTexture renderTextureWithWidth:renderWidth height:renderHeight];

        //rt is always going to be at 0,0 - can&#039;t change it.
        _rt.position = CGPointMake(0, 0);
        [[RIGameScene sharedGameScene]addChild:_rt];
        _rt.visible = YES;

        //NSLog(@&#34;\nintersection = (%u,%u,%u,%u), area = %u&#34;,x,y,w,h,numPixels);

        // Draw into the RenderTexture
        [_rt beginWithClear:0 g:0 b:0 a:0];

        // Render both sprites: first one in RED and second one in GREEN
        glColorMask(1, 0, 0, 1);
        [_sbnMain visitSprite:spr1];
        glColorMask(0, 1, 0, 1);
        [_sbnMain visitSprite:spr2];
        glColorMask(1, 1, 1, 1);

        // Get color values of intersection area
        ccColor4B *buffer = malloc( sizeof(ccColor4B) * numPixels );
        glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

        [_rt end];

        // Read buffer

        for(unsigned int i=0; i&#60;numPixels; i+=1)
        {
            ccColor4B color = buffer[i];

            if (color.r &#62; 0 &#38;&#38; color.g &#62; 0)
            {
                isCollision = YES;
                break;
            }
        }

        // Free buffer memory
        free(buffer);
        //        _sbnMain.position = oldBatchPosition;
        spr1.position = spr1OldPosition;
        spr2.position = spr2OldPosition;
        [[RIGameScene sharedGameScene]removeChild:_rt cleanup:YES];
    }

    [pool drain];

    return isCollision;
}</code></pre>
<p>And my code for custom spritebatchnode draw and visit:<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCSpriteBatchNodeExtended.h&#34;

static 	SEL selUpdate = NULL;

@implementation CCSpriteBatchNode(drawSpritesPPCD)

-(void) drawSprite:(CCSprite*)spr
{
	[super draw];

	// Optimization: Fast Dispatch
	if( textureAtlas_.totalQuads == 0 )
		return;	

	CCSprite *child;
	ccArray *array = descendants_-&#62;data;

	NSUInteger i = array-&#62;num;
	id *arr = array-&#62;arr;

	unsigned int index = 0;

	if (i &#62; 0)
	{
		while (i-- &#62; 0)
		{
			child = *arr++;

			// fast dispatch
			if (child == spr)
			{
				index = [child atlasIndex];
				child-&#62;updateMethod(child, selUpdate);
			}
		}

		// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Unneeded states: -

		BOOL newBlend = blendFunc_.src != CC_BLEND_SRC &#124;&#124; blendFunc_.dst != CC_BLEND_DST;
		if( newBlend )
			glBlendFunc( blendFunc_.src, blendFunc_.dst );

		[textureAtlas_ drawNumberOfQuads:1 fromIndex:index];

		if( newBlend )
			glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
	}
}

-(void) visitSprite:(CCSprite*)spr
{
	if (!visible_)
		return;

	glPushMatrix();

	if ( grid_ &#38;&#38; grid_.active) {
		[grid_ beforeDraw];
		[self transformAncestors];
	}

	[self transform];

	[self drawSprite:spr];

	if ( grid_ &#38;&#38; grid_.active)
		[grid_ afterDraw:self];

	glPopMatrix();
}

@end</code></pre></description>
		</item>
		<item>
			<title>MandarX on "[Box2D] How to know when the shape hits the edges"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28887#post-142524</link>
			<pubDate>Fri, 03 Feb 2012 17:03:30 +0000</pubDate>
			<dc:creator>MandarX</dc:creator>
			<guid isPermaLink="false">142524@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>thank you!
</p></description>
		</item>
		<item>
			<title>jyoung on "[Box2D] How to know when the shape hits the edges"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28887#post-142441</link>
			<pubDate>Fri, 03 Feb 2012 04:28:59 +0000</pubDate>
			<dc:creator>jyoung</dc:creator>
			<guid isPermaLink="false">142441@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Use b2EdgeShape to define the edges, then implement a ContactListener to check for collisions between your object's body and the edge shapes.
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142424</link>
			<pubDate>Fri, 03 Feb 2012 02:33:12 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142424@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>can someone please show an example on how to implement that into my code
</p></description>
		</item>
		<item>
			<title>mavrik5150 on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142397</link>
			<pubDate>Thu, 02 Feb 2012 22:01:04 +0000</pubDate>
			<dc:creator>mavrik5150</dc:creator>
			<guid isPermaLink="false">142397@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So it looks like what you have is a game in which tilting the iPhone moves the crosshairs and then the players pushes on a shoot button to fire at any object within the crosshairs. So I'm not really an expert here at Cocos2d but essentially you want to add a selector to your Shoot button that will be invoked whenever the shoot button is pressed. Within that method you want to move your collision detection code that is within the update method to instead check for a collision only when the shoot button is pressed. Sounds easy on paper, but I'm sure it will take a few steps to get done.
</p></description>
		</item>
		<item>
			<title>MandarX on "[Box2D] How to know when the shape hits the edges"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28887#post-142383</link>
			<pubDate>Thu, 02 Feb 2012 20:30:29 +0000</pubDate>
			<dc:creator>MandarX</dc:creator>
			<guid isPermaLink="false">142383@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello, </p>
<p>I'm learning Box2D</p>
<p>I put a sprite/shape in my scene/world</p>
<p>how can I know when it hits the edges?</p>
<p>(I have to play an effect)</p>
<p>thanks</p>
<p>MandarX
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142377</link>
			<pubDate>Thu, 02 Feb 2012 19:55:48 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142377@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>can you show me the code to do that
</p></description>
		</item>
		<item>
			<title>Mark Sawicki on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142369</link>
			<pubDate>Thu, 02 Feb 2012 19:24:49 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">142369@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>edit: cross posted. disregard.
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142367</link>
			<pubDate>Thu, 02 Feb 2012 19:23:29 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142367@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>now how would i check to see if the shoot button is clicked is crosshair over duck
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142366</link>
			<pubDate>Thu, 02 Feb 2012 19:22:01 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142366@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>thanks that works
</p></description>
		</item>
		<item>
			<title>mavrik5150 on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142363</link>
			<pubDate>Thu, 02 Feb 2012 19:20:41 +0000</pubDate>
			<dc:creator>mavrik5150</dc:creator>
			<guid isPermaLink="false">142363@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>You need to add the scheduleUpdate to the end of the init method in the .m file. That will then call your update method for checking for collision, your probably don't need to worry about the code I posted, since Mark is right and the problem is that you are never calling the update method to check for collisions.
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142360</link>
			<pubDate>Thu, 02 Feb 2012 19:14:15 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142360@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>in what the gameplaylayer.h file or the gamplaylayer.m file
</p></description>
		</item>
		<item>
			<title>Mark Sawicki on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142359</link>
			<pubDate>Thu, 02 Feb 2012 19:03:03 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">142359@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/77497'>kingappdesigns</a>,</p>
<p>for starters, you are missing the scheduleUpdate in the init of your GamePlayLayer. As you have it now, the update method is never called.<br />
<pre><code>[self scheduleUpdate];</code></pre></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142358</link>
			<pubDate>Thu, 02 Feb 2012 18:51:37 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142358@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>how to implement the code from mavrik5150</p>
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;GameplayLayer.h&#34;

@implementation GameplayLayer
-(id)init {
    self = [super init];
    CGSize size =[[CCDirector sharedDirector] winSize];
    if (self != nil) {

        screenHeight = size.height;
        srceenWidth = size.width;

        // enable touches
               duckSprite = [CCSprite spriteWithFile:@&#34;duck1.png&#34;
        rect:CGRectMake(0, 0, 20, 20)];
        duckSprite.position = ccp(100, screenHeight/2);

        [self addChild:duckSprite];

        CCAnimation *duckAnim = [CCAnimation animation];
        [duckAnim addFrameWithFilename:@&#34;duck1.png&#34;];
        [duckAnim addFrameWithFilename:@&#34;duck2.png&#34;];
        id duckAnimationAction =
        [CCAnimate actionWithDuration:0.5f
                            animation:duckAnim
        restoreOriginalFrame:YES];
        id repeatduckAnimation =
        [CCRepeatForever actionWithAction:duckAnimationAction];
        [duckSprite runAction:repeatduckAnimation];

        crosshair = [CCSprite spriteWithFile:@&#34;crosshair.png&#34;
                  rect:CGRectMake(0, 0, 125, 125)];
        [self addChild:crosshair];

        crosshair.position = CGPointMake( size.width / 2, size.height / 2);
        self.isAccelerometerEnabled = YES;

        [self schedule:@selector(updatecrosshair:) interval:1.0/60.f];

CCMenuItem *shoot = [CCMenuItemImage itemFromNormalImage:@&#34;Shootbutton.png&#34; selectedImage:@&#34;Shootbuttons.png&#34;];

        shoot.position = ccp(450,30);
        [self addChild:shoot];

    }

    return self;

}

-(void) updatecrosshair:(ccTime) delta{
    if (crosshair.position.x &#62;= 0 &#38;&#38; crosshair.position.x &#60;= srceenWidth) {
        crosshair.position = ccp(crosshair.position.x + tiltHorizontal , crosshair.position.y );

    } else if (crosshair.position.x &#60; 0) {
        crosshair.position = ccp (0, crosshair.position.y ); 

        } else if ( crosshair.position.x &#62; srceenWidth) {
            crosshair.position = ccp ( srceenWidth ,crosshair.position.y );

    }

    if (crosshair.position.y &#62;= 0 &#38;&#38; crosshair.position.y &#60;= screenHeight) {
        crosshair.position = ccp (crosshair.position.x , crosshair.position.y + tiltVertically);

    } else if (crosshair.position.y &#60; 0) {
        crosshair.position = ccp ( crosshair.position.x ,0 ); 

} else if ( crosshair.position.y &#62; screenHeight) {
        crosshair.position = ccp ( crosshair.position.x , screenHeight);
}

}
- (void)update:(ccTime)dt {
    [[CCDirector sharedDirector] winSize];
    CGRect duckRect = CGRectMake(
                                       duckSprite.position.x - (duckSprite.contentSize.width/2),
                                       duckSprite.position.y - (duckSprite.contentSize.height/2),
                                       duckSprite.contentSize.width,
                                       duckSprite.contentSize.height);

    CGRect crosshairRect = CGRectMake(
                                 crosshair.position.x - (crosshair.contentSize.width/2),
                                 crosshair.position.y - (crosshair.contentSize.height/2),
                                 crosshair.contentSize.width,
                                 crosshair.contentSize.height);
    if (CGRectIntersectsRect(duckRect, crosshairRect)) {
        CCLOG(@&#34;Collision!&#34;);

        }
}
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
CCLOG(@&#34;Acceleration Values are x:%f y:%f z:%f&#34;, acceleration.x , acceleration.y, acceleration.z );

    tiltHorizontal = acceleration.y * 20;
    tiltVertically = (acceleration.x + .4) *20;
    CCLOG(@&#34;tiltHorizontal is %i&#34;, tiltHorizontal );

}
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)

	// don&#039;t forget to call &#34;super dealloc&#34;
	[super dealloc];
}

@end</code></pre></description>
		</item>
		<item>
			<title>Mark Sawicki on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142357</link>
			<pubDate>Thu, 02 Feb 2012 18:46:42 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">142357@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Another alternative would be to set a flag in ccConfig.h to see more what's going on, and as @<a href='http://www.cocos2d-iphone.org/forum/profile/62189'>LittleBitStudio</a> says, it's easiest and less error prone to work from the boundingBox of the node.</p>
<p>ccConfig.h<br />
<pre><code>CC_SPRITE_DEBUG_DRAW 1
// and/or
CC_SPRITEBATCHNODE_DEBUG_DRAW 1</code></pre>
<p>.sidenote. : that first line of your update is a NOOP , you should take it out.
</p></description>
		</item>
		<item>
			<title>mavrik5150 on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142352</link>
			<pubDate>Thu, 02 Feb 2012 18:16:18 +0000</pubDate>
			<dc:creator>mavrik5150</dc:creator>
			<guid isPermaLink="false">142352@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>You may want to try adding this debugging method that makes the two Rects visible so you can actually see if they are colliding or where they are actually located (for example I had a sprite that had it's anchor point changed and by doing so the Rect was offset and causing my collision to not get called either). Basically what you want to do is in your .h file define as many Rects as you need that will get drawn </p>
<pre><code>CGRect duckDrawingRect;
CGRect crosshairDrawingRect;</code></pre>
<p>Then in you update method where you create the two rects for collision detection just have the two rects from the .h area equal those (so you would just put duckDrawingRect = duckRect; after you create duckRect and so on). Then just copy this code into you .m file and it will add a red line to the rect so you can see it </p>
<pre><code>-(void) drawBoundingBox: (CGRect) rect
{
    CGPoint vertices[4]={
        ccp(rect.origin.x,rect.origin.y),
        ccp(rect.origin.x+rect.size.width,rect.origin.y),
        ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
        ccp(rect.origin.x,rect.origin.y+rect.size.height),
    };
    ccDrawPoly(vertices, 4, YES);
}

-(void) draw
{
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    // _world-&#62;DrawDebugData();

    glColor4f(1.0, 0, 0, 1.0);
    glLineWidth(1.0f);

    [self drawBoundingBox: duckDrawingRect];
    [self drawBoundingBox: crosshairDrawingRect];

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    [super draw];
}</code></pre>
<p>And that should at least show you the rect's so you can then visually  determine if they are actually colliding since the collision detection you posted looks fine to me it could be something with the Rect's you are making.
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142335</link>
			<pubDate>Thu, 02 Feb 2012 15:52:38 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142335@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>can you show me an example
</p></description>
		</item>
		<item>
			<title>Andreas Loew on "Multiple contacts with Box2D Contactlistener"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28527#post-142282</link>
			<pubDate>Thu, 02 Feb 2012 10:11:20 +0000</pubDate>
			<dc:creator>Andreas Loew</dc:creator>
			<guid isPermaLink="false">142282@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I just made a complete tutorial which is currently available on Ray Wenderlich's blog. I guess it contains all your need.<br />
It also covers handling multiple contact points and contains a wrapper code for box2d which makes using it way easier from cocos2d.</p>
<p>=&#62; <a href="http://www.raywenderlich.com/7261/monkey-jump" rel="nofollow">http://www.raywenderlich.com/7261/monkey-jump</a>
</p></description>
		</item>
		<item>
			<title>LittleBitStudio on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142246</link>
			<pubDate>Thu, 02 Feb 2012 04:32:34 +0000</pubDate>
			<dc:creator>LittleBitStudio</dc:creator>
			<guid isPermaLink="false">142246@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Is there a reason you're not using [duckSprite boundingBox] and [crosshair boundingBox] to get your CGRect values?<br />
Do the two sprites share the same parent?
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142242</link>
			<pubDate>Thu, 02 Feb 2012 04:08:18 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142242@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>- (void)update:(ccTime)dt {<br />
    [[CCDirector sharedDirector] winSize];<br />
    CGRect duckRect = CGRectMake(<br />
                                       duckSprite.position.x - (duckSprite.contentSize.width/2),<br />
                                       duckSprite.position.y - (duckSprite.contentSize.height/2),<br />
                                       duckSprite.contentSize.width,<br />
                                       duckSprite.contentSize.height);</p>
<p>    CGRect crosshairRect = CGRectMake(<br />
                                 crosshair.position.x - (crosshair.contentSize.width/2),<br />
                                 crosshair.position.y - (crosshair.contentSize.height/2),<br />
                                 crosshair.contentSize.width,<br />
                                 crosshair.contentSize.height);<br />
    if (CGRectIntersectsRect(duckRect, crosshairRect)) {<br />
        CCLOG(@"Collision!");</p>
<p>        }<br />
}
</p></description>
		</item>
		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141936</link>
			<pubDate>Tue, 31 Jan 2012 05:04:08 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">141936@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>After optimizing my code, I now get 60fps on my 1st Generation iPhone in debug mode. :)<br />
Part of achieving the good frame rate had to do with optimizing some other code which runs in the background. Also, since I have different "classes" of sprites which interact with each other (enemy / hero / bullet) etc, not all of them need to check for collisions with everyone else. For example if hero checks for collisions with enemy, then enemy may not have to check for collisions with hero as long as hero informs enemy of a collision detection. This can be used to reduce the number of simultaneous calls to this collision checking method improving framewrate.</p>
<p>The code outlined by Dani is efficient. The only changes I made were to create a renderTexture the same size as the intersection box or 16px, whichever is greater.<br />
The reason for a minimum size, is that I received errors related to the frame buffer if the render texture was too low. I picked 16px, since some of the source code looked like it changes the size of the texture to the next power of two if it isn't a power of two.<br />
I also change the step of the loop dynamically - with larger step for larger numPixels, and smaller step for smaller numPixels.</p>
<p>As the renderTexture.sprite is always at (0,0), I move the sprites so that the origin of the intersection box is at 0,0. This is easily done since the origin of the original intersection box can be used as an offset to move the sprites.</p>
<p>After the draw routine I put the sprite back.
</p></description>
		</item>
		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141869</link>
			<pubDate>Mon, 30 Jan 2012 15:23:19 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">141869@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks Dani - Collisions perform really well for me! (on my 1st generation iPhone).</p>
<p>When the bounding boxes of both sprites intersect = 55fps<br />
When the actual sprites overlap = 55fps.</p>
<p>Every few seconds it drops to 47fps (barely for an instant), so its almost a constant 55fps.<br />
It didn't seem to make any difference whether I was on debug or release build.</p>
<p>I need to test out many more scenarios for performance, but its looking good so far.
</p></description>
		</item>
		<item>
			<title>Dani on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141867</link>
			<pubDate>Mon, 30 Jan 2012 14:53:40 +0000</pubDate>
			<dc:creator>Dani</dc:creator>
			<guid isPermaLink="false">141867@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p><strong>@Martin</strong>: what Kobold2D does it's not pixel perfect in all situations, only works for non rotated sprites (or that's what I read time ago <a href="http://www.learn-cocos2d.com/2011/12/fast-pixelperfect-collision-detection-cocos2d-code-1of2/">here</a>).</p>
<p>The most easy and exact collision detection is to read what's on the screen after making all tranformations, but that seems to be expensive if it's done without diving into OpenGL waters and making substantial changes to cocos2d core, I suppose.</p>
<p>I think that some people here are still using this pixel perfect method and have improved it, so they should know how to optimize it, and the limitations.
</p></description>
		</item>
		<item>
			<title>Martin on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141862</link>
			<pubDate>Mon, 30 Jan 2012 14:19:36 +0000</pubDate>
			<dc:creator>Martin</dc:creator>
			<guid isPermaLink="false">141862@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Doesn't kobold2d come with a pixel perfect collision example?
</p></description>
		</item>
		<item>
			<title>Dani on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141859</link>
			<pubDate>Mon, 30 Jan 2012 12:47:10 +0000</pubDate>
			<dc:creator>Dani</dc:creator>
			<guid isPermaLink="false">141859@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p><strong>@Some Guy</strong>: Hello man.</p>
<p>I don't work in this collision method anymore, but I remember some things. If you make your <em>CCRenderTexture</em> smaller than screen size and place it in, for instance, (23,60), you must move the sprites involved in the collision to that location. I was using a <em>CCSpriteBatchNode</em>, so I moved the whole batch node, something like this (<em>_sbnMain</em> is the batch node):</p>
<pre><code>-(BOOL) isCollisionBetweenSpriteA:(CCSprite*)spr1 spriteB:(CCSprite*)spr2 pixelPerfect:(BOOL)pp
{
    BOOL isCollision = NO;
    CGRect intersection = CGRectIntersection([spr1 boundingBox], [spr2 boundingBox]);

    // Look for simple bounding box collision
    if (!CGRectIsEmpty(intersection))
	{
        // If we&#039;re not checking for pixel perfect collisions, return true
        if (!pp) {return YES;}

		// Offset
		int offsetX = -spr1.position.x + K_RT_WIDTH*0.5f;
		int offsetY = -spr1.position.y + K_RT_HEIGHT*0.5f;

        // Get intersection info
        unsigned int x = intersection.origin.x + offsetX;
        unsigned int y = intersection.origin.y + offsetY;
        unsigned int w = intersection.size.width;
        unsigned int h = intersection.size.height;
        unsigned int numPixels = w * h;

		_sbnMain.position = ccp(offsetX,offsetY);

		// Draw into the RenderTexture

		[_rt begin];
		[_clearSprite visit];

		// Render both sprites: first one in RED and second one in GREEN
        glColorMask(1, 0, 0, 1);
        [_sbnMain visitSprite:spr1];
        glColorMask(0, 1, 0, 1);
        [_sbnMain visitSprite:spr2];
        glColorMask(1, 1, 1, 1);

        ccColor4B *buffer = malloc( sizeof(ccColor4B) * numPixels );
        glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

        [_rt end];

		_sbnMain.position = ccp(0,0);

        // Read buffer
        unsigned int step = 1;
        for(unsigned int i=0; i&#60;numPixels; i+=step)
        {
            ccColor4B color = buffer[i];

            if (color.r &#62; 0 &#38;&#38; color.g &#62; 0)
            {
                isCollision = YES;
                break;
            }
        }

        // Free buffer memory
        free(buffer);
    }

    return isCollision;
}</code></pre>
<p>I'm not sure, but if I remember well, you cannot change the <strong>anchor point</strong> of a <em>CCRenderTexture</em>, so it's always (0.5f,0.5f).</p>
<p>Also, to visit only one sprite from the batch node, you can use a category like this:</p>
<p><strong>CCSpriteBatchNodeExtended.h</strong></p>
<pre><code>@interface CCSpriteBatchNode(drawSpritesPPCD)

-(void) drawSprite:(CCSprite*)spr;
-(void) visitSprite:(CCSprite*)spr;

@end</code></pre>
<p><strong>CCSpriteBatchNodeExtended.m</strong></p>
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCSpriteBatchNodeExtended.h&#34;

static 	SEL selUpdate = NULL;

@implementation CCSpriteBatchNode(drawSpritesPPCD)

+(void) initialize
{
	if ( self == [CCSpriteBatchNode class] ) {
		selUpdate = @selector(updateTransform);
	}
}

-(void) drawSprite:(CCSprite*)spr
{
	[super draw];

	// Optimization: Fast Dispatch
	if( textureAtlas_.totalQuads == 0 )
		return;	

	CCSprite *child;
	ccArray *array = descendants_-&#62;data;

	NSUInteger i = array-&#62;num;
	id *arr = array-&#62;arr;

	unsigned int index = 0;

	if (i &#62; 0)
	{
		while (i-- &#62; 0)
		{
			child = *arr++;

			// fast dispatch
			if (child == spr)
			{
				index = [child atlasIndex];
				child-&#62;updateMethod(child, selUpdate);
			}
		}

		// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Unneeded states: -

		BOOL newBlend = blendFunc_.src != CC_BLEND_SRC &#124;&#124; blendFunc_.dst != CC_BLEND_DST;
		if( newBlend )
			glBlendFunc( blendFunc_.src, blendFunc_.dst );

		[textureAtlas_ drawNumberOfQuads:1 fromIndex:index];

		if( newBlend )
			glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
	}
}

-(void) visitSprite:(CCSprite*)spr
{
	if (!visible_)
		return;

	glPushMatrix();

	if ( grid_ &#38;&#38; grid_.active) {
		[grid_ beforeDraw];
		[self transformAncestors];
	}

	[self transform];

	[self drawSprite:spr];

	if ( grid_ &#38;&#38; grid_.active)
		[grid_ afterDraw:self];

	glPopMatrix();
}

@end</code></pre>
<p>It's old code for cocos2d v1.0, I don't know if it's still working. But the idea is to modify the draw and visit method from CCSpriteBatchNode to draw only the sprite you are passing as parameter.</p>
<p>Hope this helps.
</p></description>
		</item>
		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141843</link>
			<pubDate>Mon, 30 Jan 2012 10:00:19 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">141843@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Also, you have mentioned modifying the draw and visit methods when using spriteBatchNodes, so that only the sprite concerned is passed in - Can you show me how you did that? (I don't understand the openGl API and how the draw &#38; visit methods work).</p>
<p>Right now, I get the currently displayed flame from the sprite, create a separate sprite, and visit the new sprite instead.
</p></description>
		</item>
		<item>
			<title>Some Guy on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522/page/3#post-141842</link>
			<pubDate>Mon, 30 Jan 2012 09:56:53 +0000</pubDate>
			<dc:creator>Some Guy</dc:creator>
			<guid isPermaLink="false">141842@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I have run into some trouble trying to integrate Dani's code with my project. I hope you can help me out:<br />
If I integrate the code without any changes, then it works as expected. The problem appears when I try to create the CCRenderTexture of a size other than the screen size, and try to position it at a location other than (winSize*width*0.5f, winSize*height*0.5f).</p>
<p>When I set the size to be less than screen size, collisions seem to be detected even when there is a noticeable amount of space between the colliding sprites (~10px?)<br />
Likewise, regardless of where  I specify the location, it seems that the render texture starts at 0,0 till the height, width specified.</p>
<p>Since many of you have created 10x10 size renderTextures, and repositioned them and the sprites, I was wondering if you could show me some sample code of what you did. I'm probably doing something incorrect, but I can't figure it out.
</p></description>
		</item>

	</channel>
</rss>

