cocos2d-x 不规则碰撞检测 【转载】
原文: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;
}
最新文章
- NC JDK报tools.jar错误(61版本)
- JMeter学习(一)工具简单介绍
- [LeetCode] Longest Increasing Subsequence
- vim使用快捷键
- if语句代码优化
- 使用异步 I/O 大大提高应用程序的性能
- Sizzle一步步实现所有功能(基本筛选)
- STM32 驱动1602液晶
- webpack搭建服务器,随时修改刷新
- Bluetooth A2DP --Audio payload type
- [BZOJ1503] [NOI2004] 郁闷的出纳员 (treap)
- BZOJ1431 : MLand
- sublime 浏览器快捷键设置
- XXL-JOB之本地环境搭建
- postman接口测试
- Saltstack报错小记
- java中 Java.lang.Long.parseLong()方法
- 【Spring】12、Spring Security 四种使用方式
- for循环案例
- ubuntu 解压命令
热门文章
- 洛谷 3740 [HAOI2014]贴海报
- IDEA建立一个可运行的struts2项目
- nyoj 55 懒省事的小明(priority_queue优先队列)
- hdu 1811拓扑排序+并查集(容器实现)
- Memory+SLES 11/12 OS Tuning &; Optimization
- python实现汉诺塔算法
- Ubuntu 16.04安装Meld文件比对工具替代Beyond Compare
- 晶振虚焊导致TI 28335 DSP 烧写FLASH后,连接仿真器时正常工作,拔掉仿真器却不能启动运行
- 项目中应用到的框架和技术之二——ol3-ext
- Clojure: 寻找项目依赖项目