Note that there are some explanatory texts on larger screens.

plurals
  1. POcocos2d and glReadPixels don't work?
    primarykey
    data
    text
    <p>i have a problem with cocos2d and glReadPixels because don't work correctly. I found in web a code for pixel perfect collision and i modified for my app, but with the animation or more fast animation don't work.</p> <p>This is the code:</p> <p><code>-(BOOL) isCollisionBetweenSpriteA:(CCSprite*)spr1 spriteB:(CCSprite*)spr2 pixelPerfect:(BOOL)pp { BOOL isCollision = NO; CGRect intersection = CGRectIntersection([spr1 boundingBox], [spr2 boundingBox]);</p> <pre><code>// Look for simple bounding box collision if (!CGRectIsEmpty(intersection)) { // If we're not checking for pixel perfect collisions, return true if (!pp) {return YES;} // Get intersection info unsigned int x = intersection.origin.x; unsigned int y = intersection.origin.y; unsigned int w = intersection.size.width; unsigned int h = intersection.size.height; unsigned int numPixels = w * h; //NSLog(@"\nintersection = (%u,%u,%u,%u), area = %u",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); [spr1 visit]; glColorMask(0, 1, 0, 1); [spr2 visit]; 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); /******* All this is for testing purposes *********/ // Draw the intersection rectangle in BLUE (testing purposes) /**************************************************/ [_rt end]; // Read buffer unsigned int step = 1; for(unsigned int q=0; q&lt;1; q+=step) { ccColor4B color = buffer[q]; if (color.r &gt; 0 &amp;&amp; color.g &gt; 0) { isCollision = YES; break; } } // Free buffer memory free(buffer); } return isCollision; </code></pre> <p>}</code></p> <p>where is the problem?I tried but nothing.</p> <p>Thank you very much. regards.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload