点对点碰撞检测
来源:互联网 发布:手机卸载软件 编辑:程序博客网 时间:2024/06/08 10:08
-(BOOL)pixelMaskIntersectsRegularNode:(CCNode*)other
{
CGRectintersectRect =[self intersectRectInPixels:selfotherNode:other];
// check if any of the flags in the pixelMask are set in intersection
NSUIntegermaxX =intersectRect.origin.x+ intersectRect.size.width;
NSUIntegermaxY =intersectRect.origin.y+ intersectRect.size.height;
for(NSUIntegery =intersectRect.origin.y;y <maxY; y++)
{
for(NSUIntegerx =intersectRect.origin.x;x <maxX; x++)
{
NSUIntegerindex =y * pixelMaskWidth +x;
returnpixelMask[index];
}
}
returnNO;
}
-(CGRect)intersectRectInPixels:(CCNode*)nodeotherNode:(CCNode*)other
{
CGRectmyBBox =[node boundingBox];
CGRectotherBBox =[other boundingBox];
CGRectintersectRect =CGRectIntersection(myBBox,otherBBox);
// transform the rect to the sprite's space and convert points to pixels
intersectRect.origin= [nodeconvertToNodeSpace:intersectRect.origin];
returnCC_RECT_POINTS_TO_PIXELS(intersectRect);
}
-(BOOL)pixelMaskIntersectsPixelMaskSprite:(KKPixelMaskSprite*)other
{
CGRectintersectSelf =[self intersectRectInPixels:selfotherNode:other];
CGRectintersectOther =[self intersectRectInPixels:otherotherNode:self];
NSUIntegeroriginOffsetX =intersectOther.origin.x- intersectSelf.origin.x;
NSUIntegeroriginOffsetY =intersectOther.origin.y- intersectSelf.origin.y;
NSUIntegerotherPixelMaskWidth =other.pixelMaskWidth;
BOOL*otherPixelMask =other.pixelMask;
// check if any of the flags in the pixelMask are set in intersection area
NSUIntegermaxX =intersectSelf.origin.x+ intersectSelf.size.width;
NSUIntegermaxY =intersectSelf.origin.y+ intersectSelf.size.height;
for(NSUIntegery =intersectSelf.origin.y;y <maxY; y++)
{
for(NSUIntegerx =intersectSelf.origin.x;x <maxX; x++)
{
NSUIntegerindex =y * pixelMaskWidth +x;
if(pixelMask[index])
{
// check if there's a pixel set at the same location
// in the pixelMask of the other sprite
NSUIntegerotherX =x +originOffsetX;
NSUIntegerotherY =y +originOffsetY;
NSUIntegerotherIndex =otherY * otherPixelMaskWidth +otherX;
if(otherPixelMask[otherIndex])
{
returnYES;
}
}
}
}
returnNO;
}
-(BOOL)pixelMaskIntersectsNode:(CCNode*)other
{
if(rotation_!= 0.0f|| other.rotation!= 0.0f||
self.scale!= 1.0f|| other.scale!= 1.0f)
{
CCLOG(@"either or both nodes are rotated and/or scaled, returning NO!");
returnNO;
}
if([selfintersectsNode:other])
{
if([otherisKindOfClass:PixelMaskSpriteClass])
{
KKPixelMaskSprite*maskSprite =(KKPixelMaskSprite*)other;
return[self pixelMaskIntersectsPixelMaskSprite:maskSprite];
}
else
{
return[self pixelMaskIntersectsRegularNode:other];
}
}
returnNO;
}
- 点对点碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- 关于信号sigprocmask
- usb鼠标枚举过程深度解析(下)
- delphi的Format
- SD卡 家族的发展
- python modbus_tk库 学习记录
- 点对点碰撞检测
- 为什么编程语言以及数据库要从1970年1月1日开始计算时
- PF_PACKET和AF_PACKET的不同
- ORACLE RAC中grid和oracle中环境变量设置和相关命令使用原则
- oracle性能优化篇——创建索引应注意的问题
- 设置控制台应用程序字体颜色
- Java程序员应该了解的10个面向对象设计原则
- 解决在CentOS 5.5 yum源下载慢的办法
- ubuntu11.10英文版通过网络和 smbfs 命令访问 Windows XP Pro 中文版的 NTFS 分区共享文件夹