原文: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;

}

cocos2d-x 不规则碰撞检测 【转载】的更多相关文章

  1. Cocos2d Box2D之碰撞检测

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 在Box2D中碰撞事件由b2ContactListener类函数实现,b2ContactListener是Box2D提供的抽象类,它的抽象 ...

  2. Duiib 创建不规则窗口(转载)

    方法一: 转载:http://blog.csdn.net/chenlycly/article/details/46447297 转载:http://blog.csdn.net/harvic880925 ...

  3. Duilib 创建不规则窗口(转载)

    方法一: 转载:http://blog.csdn.net/chenlycly/article/details/46447297 转载:http://blog.csdn.net/harvic880925 ...

  4. BitmapData类介绍

    今天介绍另外一个比较常用和中高级难度的类:BitmapData 用好这个类,可以说是半支脚踏入了Flash高手的大门···(主要是不是太多的人精通这个··呵呵··)我也可以趁这篇文章的机会好好巩固+学 ...

  5. cocos2d(CCSprite绑定不规则刚体与精灵一起移动)

    对于不规则的精灵我们可以借助PhysicsEditor来制作shape , 对于地图可以使用Tiled软件制作瓷砖地图. 今天主要记录一下如何把CCSprite与不规则刚体进行绑定,然后一起移动 // ...

  6. 转载+自练(莫喷)怎样在cocos2d 2.1.4里面使用动画和Texture Packer

    本文实践自 Ray Wenderlich.Tony Dahbura 的文章<How to Use Animations and Sprite Sheets in Cocos2D 2.X>, ...

  7. Cocos2d-三维拾取Ray-AABB碰撞检测算法【转】

    1.三维拾取技术 在3D游戏中通常会有这样的需求,用户可以选取3D世界中的某些物体进行如拖拽等操作,这时便需要程序通过将二维屏幕上的点坐标转换为三维世界中的坐标,并进行比对,这个过程就需要用到三维拾取 ...

  8. Cocos2d-x3.2 使用物理引擎进行碰撞检测[转]

    通常在游戏简单逻辑判断和模拟真实的物理世界时,我们只需要在定时器中判断游戏中各个精灵的条件是否满足判断条件就可以了.例如,在飞机大战中,判断我方子弹和敌机是否发生碰撞一般在定时器中通过敌机所在位置的矩 ...

  9. Cocos2d-x3.2总结---使用物理引擎进行碰撞检测

    [转自]: http://blog.csdn.net/cbbbc/article/details/38541099 通常在游戏简单逻辑判断和模拟真实的物理世界时,我们只需要在定时器中判断游戏中各个精灵 ...

随机推荐

  1. 创建Maven版Java工程

    步骤: 创建成功后,如图:

  2. RequestMapping_PathVariable注解

    [@PathVariable 映射URL绑定的占位符] 1.带占位符的URL是Spring 3.0 新增的功能,该功能在Spring MVC向 REST 目标挺进发展过程中具有里程碑的意义. 2.通过 ...

  3. Android layer-list(1)

     Android layer-list(1) Android layer-list,顾名思义,实现列表组合后形成的图层,写一个例子. activity_main.xml文件: <?xml v ...

  4. hdu 1811拓扑排序+并查集(容器实现)

    http://www.cnblogs.com/newpanderking/archive/2012/10/18/2729566.html #include<stdio.h> #includ ...

  5. The Balance POJ 2142 扩展欧几里得

    Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...

  6. java String长度与varchar长度匹配理解(字符和字节长度理解)

    java String长度与varchar长度匹配理解(字符和字节长度理解) string中的length()长度,返回的是char的数量,每个char可以存储世界上任何类型的文字和字符,一个char ...

  7. scp: useful commands

    Examples Copy the file "foobar.txt" from a remote host to the local host $ scp your_userna ...

  8. C++中设计一个类,使其不能继承

    1.C++11中已经有了final关键字:它的作用是指定类的虚函数不能被该类的继承类覆盖(override),或者是指定一个类成为一个不能被继承的类(final class) 2.派生类用调用基类的构 ...

  9. [Algorithm] Determine if two strings are an anagram

    The anagram test is commonly used to demonstrate how an naive implementation can perform significant ...

  10. [LeetCode][Java] Palindrome Number

    题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...