0
我一直坚持了几个星期,现在试图弄清楚如何忽略精灵的透明区域的触摸。我一直在尝试使用本教程 - http://www.learn-cocos2d.com/2011/12/fast-pixelperfect-collision-detection-cocos2d-code-1of2/无法完成像素完美碰撞。这是目前我的代码看起来是:忽略cocos2d中精灵的透明区域
-(void)checkTap:(CGPoint)touch{
BOOL yesNo = NO;
if(yesNo == NO)
{
sprTap.position = ccp(touch.x, touch.y);
}}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
[self checkTap:location];
touchFlag = 0;
for(int i = 0; i < [sprArray count]; i++)
{
KKPixelMaskSprite *sprite = (KKPixelMaskSprite *)[sprArray objectAtIndex:i];
if([sprTap intersectsNode:sprite])
{
selectedSprite = sprite;
touchFlag = 1;
break;
}
}}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
[sprTap setPosition:location];
if(touchFlag == 1)
{
_spriteTouch = TRUE;
[selectedSprite setPosition:location];
}
else
{
for(int i = 0; i < [sprArray count]; i++)
{
KKPixelMaskSprite *sprite = (KKPixelMaskSprite *)[sprArray objectAtIndex:i];
if([sprTap intersectsNode:sprite])
{
selectedSprite = sprite;
touchFlag = 1;
break;
}
}
}
}}
与此问题是,当sprTap的边框与精灵的边框相交,它的动作都和因为我的精灵是不完美的正方形,赢得”不要做。我也试过pixelMaskIntersectsNode,但似乎也没有工作。我还可以忽略对精灵透明部分的接触吗?请帮帮我。
谢谢你的回答。我会试一试。但是,对于这个答案我有一个疑问,如果有2个或更多可以被触摸的精灵,我该如何实现? – user1597438 2013-02-18 11:39:32
我有点想出如何实现,但我有一个问题。我的精灵应该根据滑动方向移动。我的问题是,只要我向上滑动,精灵就会向左移动。这是为什么? – user1597438 2013-02-19 02:54:52
引用此:http://stackoverflow.com/questions/14953630/path-is-not-detected-properly-in-cocos2d/14954003#14954003 – Guru 2013-02-19 09:34:35