一般情况下,我们使用sprite->getBoundingBox()->containsPoint(touchLocation)
来判断是否触摸到了一个精灵.
需求是万变的,经常需求要求我们触摸时判断一个不规则图形
1 2 3 4 5 6 7 8 9 10 11 |
CCRenderTexture* render = CCRenderTexture::create(CCDirector::sharedDirector()->getWinSize().width, CCDirector::sharedDirector()->getWinSize().height); render->begin(); sprite->visit(); GLubyte pColor[4]; glReadPixels(location.x,location.y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,&pColor[0]); if (pColor[3] != 0) { render->end(); return false; } render->end(); return true; |