Cocos2Dの特定の領域内でスプライトが検出されないようにしたい。私のゲームでは、スプライトが底から産み出され、タッチで検出されます。 newArea(newAreaではz方向が1)の下からスプライトが生成されるnewArea(領域)を追加しました。今、この特定の分野で私はタッチを検出したくありません(私はここに追加機能を追加する必要があります)。どうすればいいですか?以下は私が使用しているコードです。 touchesBeganでCocos2Dの特定の領域(スプライトでもある)内でスプライトが検出されないようにするにはどうすればよいですか?
CCSprite *background = [CCSprite spriteWithFile:@"bgmain.png"];
background.position = ccp(winSize.width/2, winSize.height/1.7);
[self addChild:background];
CCSprite *newArea = [CCSprite spriteWithFile:@"newImage.png"];
newArea.position = ccp(winSize.width/2, winSize.height/17);
[self addChild:newArea z:1];
//タッチ検出のための
- (void)selectSpriteForTouch:(CGPoint)touchLocation
{
for (CCSprite *sprite in targets)
{
if (CGRectContainsPoint([sprite boundingBox], touchLocation))
{
switch (sprite.tag) {
case 1:
[[SimpleAudioEngine sharedEngine] playEffect:@"button1.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 2:
[[SimpleAudioEngine sharedEngine] playEffect:@"button2.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 3:
[[SimpleAudioEngine sharedEngine] playEffect:@"button3.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 4:
[[SimpleAudioEngine sharedEngine] playEffect:@"button4.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 5:
[[SimpleAudioEngine sharedEngine] playEffect:@"button5.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 6:
[[SimpleAudioEngine sharedEngine] playEffect:@"button6.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 7:
[[SimpleAudioEngine sharedEngine] playEffect:@"button7.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 8:
[[SimpleAudioEngine sharedEngine] playEffect:@"button8.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 9:
[[SimpleAudioEngine sharedEngine] playEffect:@"button9.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
case 10:
[[SimpleAudioEngine sharedEngine] playEffect:@"button10.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
break;
default:
break;
}
NSLog(@"target.tag %d",sprite.tag);
[targets removeObject:sprite];
[self balloonBlastAnimation:sprite];
[sprite.parent removeChild:sprite cleanup:YES];
break;
}
}
}
-(void) removeSprite:(CCSprite*) s
{
s.visible = FALSE;
[self removeChild:s cleanup:YES];
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for(UITouch *touch in touches)
{
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
[self selectSpriteForTouch:location];
NSLog(@"touch was detected");
}
}
ありがとうございました。それは助け:) –