原文:http://www.2cto.com/kf/201401/272331.html

//判断有没有点到有材质的部分, p_point相对, CCSprite坐标  (p_point是相对 Sprite锚点的偏移)

bool isClickTheRealSprite(cocos2d::CCSprite* p_sprite, const cocos2d::CCPoint p_point)

{

CCSize l_sizeInPixel = p_sprite->getContentSize();

//得到相对,Sprite左下的偏移

int l_iX = (int)(l_sizeInPixel.width/2.0f + p_point.x);

int l_iY = (int)(l_sizeInPixel.height/2.0f + (int)p_point.y);

CCPoint l_pointBL = ccp(l_iX, l_iY);

CCRect l_rect = CCRect(0, 0, l_sizeInPixel.width, l_sizeInPixel.height);

if(!(l_rect.containsPoint(l_pointBL))){

return false;

}

//开辟出空内存buffer

//unsigned char* l_buffer = (unsigned char*)malloc(l_sizeInPixel.width * l_sizeInPixel.height * 4);

//memset(l_buffer, 0, l_sizeInPixel.width * l_sizeInPixel.height * 4);

uint8_t l_buffer[4];

//写内存

CCSize size = p_sprite->getParent()->getContentSize();

CCRenderTexture* l_renderTexture = CCRenderTexture::create(l_sizeInPixel.width, l_sizeInPixel.height, kCCTexture2DPixelFormat_RGBA8888);

//l_renderTexture->begin();

l_renderTexture->beginWithClear(0, 0, 0, 0);

p_sprite->draw();

glReadPixels(l_pointBL.x, l_pointBL.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, l_buffer);

l_renderTexture->end();

//透明度

//int l_iValue_A = l_buffer[4*(int)(l_pointBL.y*l_sizeInPixel.width + l_pointBL.x)+3];

int l_iValue_A = l_buffer[3];

//free(l_buffer);

if(l_iValue_A < 5 ){

return false;

}

return true;

}

最新文章

  1. NC JDK报tools.jar错误(61版本)
  2. JMeter学习(一)工具简单介绍
  3. [LeetCode] Longest Increasing Subsequence
  4. vim使用快捷键
  5. if语句代码优化
  6. 使用异步 I/O 大大提高应用程序的性能
  7. Sizzle一步步实现所有功能(基本筛选)
  8. STM32 驱动1602液晶
  9. webpack搭建服务器,随时修改刷新
  10. Bluetooth A2DP --Audio payload type
  11. [BZOJ1503] [NOI2004] 郁闷的出纳员 (treap)
  12. BZOJ1431 : MLand
  13. sublime 浏览器快捷键设置
  14. XXL-JOB之本地环境搭建
  15. postman接口测试
  16. Saltstack报错小记
  17. java中 Java.lang.Long.parseLong()方法
  18. 【Spring】12、Spring Security 四种使用方式
  19. for循环案例
  20. ubuntu 解压命令

热门文章

  1. 洛谷 3740 [HAOI2014]贴海报
  2. IDEA建立一个可运行的struts2项目
  3. nyoj 55 懒省事的小明(priority_queue优先队列)
  4. hdu 1811拓扑排序+并查集(容器实现)
  5. Memory+SLES 11/12 OS Tuning &amp; Optimization
  6. python实现汉诺塔算法
  7. Ubuntu 16.04安装Meld文件比对工具替代Beyond Compare
  8. 晶振虚焊导致TI 28335 DSP 烧写FLASH后,连接仿真器时正常工作,拔掉仿真器却不能启动运行
  9. 项目中应用到的框架和技术之二——ol3-ext
  10. Clojure: 寻找项目依赖项目