Use*_*234 9 objective-c cocos2d-iphone
我是Cocos2d的初学者.我有一个精灵,我想忽略那个精灵的透明区域的触摸.
我知道这个答案Cocos2d 2.0 - 忽略对图层/精灵的透明区域的触摸,以及这篇伟大的文章http://www.learn-cocos2d.com/2011/12/fast-pixelperfect-collision-detection-cocos2d -code-1of2 /.
我能够使它与KKPixelMaskSprite一起使用,但只有在文件中使用sprite时才能使用,但不能从批处理节点使用sprite.每当我使用批处理节点(Sprite表)时,为了获得精灵,它就会停止工作.
我有彼此不同的精灵,我想以这种方式检测 - >如果触摸是在当前的精灵边界框中,那个部分在精灵上是透明的还是没有?
PSI使用cocos2d 1.0.我现在不想使用任何物理引擎,我只想忽略精灵透明区域的触摸(使用批处理节点创建).我该怎么做?或者可能有任何工具可以帮助吗?
非常感谢提前.
您可以使用 CGMutablePathRef 进行非矩形精灵碰撞检测。
//检查
CGPoint loc =[mySprite convertToNodeSpace:touchPoint];
if([mySprite isPointInsideMap:loc])
{
//touched inside..
}
//Add this method in your MySprite class derived from CCSprite.
-(bool)isPointInsideMap:(CGPoint)inPoint
{
if (CGPathContainsPoint(mCollisionPath, NULL, inPoint, NO) )
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
////创建路径
CGMutablePathRef mCollisionPath = CGPathCreateMutable();
CGPathMoveToPoint(mCollisionPath, NULL, 0, 0 );
CGPathAddLineToPoint(mCollisionPath, NULL, 11, 82 );
CGPathAddLineToPoint(mCollisionPath, NULL, 42, 152 );
CGPathAddLineToPoint(mCollisionPath, NULL, 86, 202 );
CGPathAddLineToPoint(mCollisionPath, NULL, 169, 13 );
CGPathCloseSubpath(mCollisionPath);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2272 次 |
| 最近记录: |