cocos2dx 3.0之判断点击精灵透明区域
来源:互联网 发布:江苏软件考试网 编辑:程序博客网 时间:2024/04/20 05:47
本站文章转载务必在明显处注明:原文链接 http://blog.csdn.net/cjsen/article/details/17241027
前言
在Layer层中 如何判断触摸事件 在图片精灵中,触摸点是否在图片的透明区域
实现
if(p1.containsPoint(p)){ int8_t data[4]; Point touchPoint = node -> convertTouchToNodeSpace(touch); Point location = Point((touchPoint.x) * CC_CONTENT_SCALE_FACTOR(), (touchPoint.y) * CC_CONTENT_SCALE_FACTOR()); RenderTexture* renderTexture = RenderTexture::create(1* CC_CONTENT_SCALE_FACTOR(),1 * CC_CONTENT_SCALE_FACTOR(), Texture2D::PixelFormat::RGBA8888); renderTexture->beginWithClear(0,0,0,0);//只保存渲染一个像素的数据 Point oldPos = node->getPosition(); Point oldAnchor = node->getAnchorPoint(); node->setAnchorPoint(Point(0,0)); node->setPosition(Point(-location.x, -location.y)); node->visit(); node->setAnchorPoint(oldAnchor); node->setPosition(oldPos); glReadPixels(0,0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data); renderTexture->end(); renderTexture->release(); //检测alpha值 CCLOG("X:%.0f y:%.0f R: %d, G: %d, B: %d, A: %d tag:%d",location.x ,location.y, data[0], data[1], data[2], data[3],this->getTag()); if(data[0] || data[1] || data[2] || data[3]) { CCLOG("非透明"); }else{ CCLOG("透明"); } }
其中当触摸事件为已在精灵内部,进而再判断是否在透明区域,其中node为要判断的精灵
0 0
- cocos2dx 3.0之判断点击精灵透明区域
- cocos2dx 3.x判断node点击区域是否透明
- 非透明区域点击判断
- cocos2dx 检测是否点击到了图片的透明区域
- cocos2dx 检测是否点击到了图片的透明区域
- cocos2dx 精灵点击事件
- 判断精灵的点击
- Cocos2dx之精灵创建
- Cocos2dx之精灵坐标系
- Cocos2dx之精灵批处理
- Cocos2dx图片像素颜色值获取,可用于判断是否是图片的透明区域
- Cocos2dx Widget 按钮透明区域过滤
- cocos2dx不响应透明区域事件
- 点击精灵区域消除,点击其他区域创建新精灵。(模拟放置炸弹,及引爆)
- 判断鼠标的点击区域
- 图片点击之区域点击
- cocos2dx-3.0(4)------Sprite 精灵
- Cocos2d-x判断点击到一个精灵
- 在SELS中配置SSH用户等效性时,遇到错误:PRNG is not seeded
- 通用2014职称计算机考试excel2003 word2003 internet题库
- AfxBeginThread
- 人脸识别的现状
- LeetCode — Linked List Cycle 解题报告
- cocos2dx 3.0之判断点击精灵透明区域
- 写sfss时遇到的问题
- codeforce日记 371A
- Struts2(服务器端)输入校验
- 关于图像特征提取
- 组合数学小结
- 单例模式(Singleton Pattern)案例解析
- struts2校验器概述3
- Linux Shell 编程实战技巧