(转)cocos2d-x 不规则图形碰撞检测(像素级碰撞检测)
来源:互联网 发布:excel合并保留数据 编辑:程序博客网 时间:2024/06/05 01:12
原文出处:http://www.2cto.com/kf/201401/272331.html
在游戏中,有时会用到判断是否点击到一张图的有色部分,即非透明区域; 或者是判断不规则图片的碰撞的判断。
//判断有没有点到有材质的部分, p_point相对, CCSprite坐标bool Tools::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;}
0 0
- (转)cocos2d-x 不规则图形碰撞检测(像素级碰撞检测)
- cocos2d-x 不规则图形碰撞检测
- cocos2d-x像素碰撞检测
- COCOS2D-X 像素级碰撞检测
- 像素完美碰撞检测(使用cocos2d-x)
- cocos2d-x 碰撞检测
- cocos2d-x 碰撞检测
- cocos2d-x 检测碰撞
- Cocos2d-x碰撞检测
- 关于两个不规则图形的碰撞检测
- cocos2d-x如何检测碰撞
- cocos2d-x 矩形碰撞检测
- Cocos2d-x如何检测碰撞
- cocos2d-x 检测矩形碰撞
- cocos2d-x中的碰撞检测
- cocos2d-x的碰撞检测
- cocos2d-x如何检测碰撞
- cocos2d-x 检测矩形碰撞
- Struts2标签遍历<s:iterator>集合
- Android杂谈--ListView之SimpleAdapter的使用
- MQ测试JAVA客户端实现源码
- Java NIO原理图文分析及代码实现
- 条款18:让接口容易被正确使用,不易被误用
- (转)cocos2d-x 不规则图形碰撞检测(像素级碰撞检测)
- Ubunt下的软件集
- inline、block、inline-block的区别
- C/C++
- 匈牙利算法学习资料
- /bin/bash: line 0: fg: no job control一般解决方法
- android 工具类 DateUtil
- Construct Binary Tree from Inorder and Postorder Traversal
- 解决tomcat6.0启动一闪而过的方法