开发者

In Cocos2d/OpenGL-ES check pixel of previous draw?

I'm drawing some lines in cocos2d (using handy ccDrawLine), nothing fancy, but i want to check if my animated line hits something. I could do some math calculations for some objects, but fo开发者_开发百科r some dynamic parts in the scene it would be much easier if i could do:

if pixel not black at (x,y)
  // line will hit something
  do handleCollisionDetectedAt(x,y)

What would you suggest? At least what would you suggest if it would be simple OpenGL ES.


Found solution:

GLubyte pColor[4];
glReadPixels(x,y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,&pColor[0]);
int red = pColor[0];
int green = pColor[1];
int blue = pColor[2];   

NSLog(@"(R,G,B) = (%d,%d,%d)",red,green,blue);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜