我是新手cocos2D
,检测碰撞方法有问题,CGRectIntersectsRect
即使物体被移除也是如此,碰撞后需要显示 100+ 发短信CCLabelTTF
一次,但它是多次添加的。低于守则
-(void)detectBonousPtCollision
{
for (CCSprite *sprite in pointsArray)
{
NSLog(@"tag value %d",sprite.tag);
if (CGRectIntersectsRect(playerSprite.boundingBox, sprite.boundingBox))
{
[self removeChild:sprite cleanup:YES];
[label setString:[NSString stringWithFormat:@"score %d",totalScore = totalScore+100]];
CCLabelTTF *ptLabel = [CCLabelTTF labelWithString:@"100+" fontName:@"Marker Felt" fontSize:20];
ptLabel.position = ccp(playerSprite.position.x, playerSprite.position.y);
ptLabel.tag = 102;
[self addChild:ptLabel];
CCSequence *sequence = [CCSequence actions:
[CCMoveTo actionWithDuration:3 position:ccp(playerSprite.position.x+10, playerSprite.position.y+10)],
[CCCallFunc actionWithTarget:self selector:@selector(afterAnimation:)],
nil];
[ptLabel runAction:sequence];
//[[SimpleAudioEngine sharedEngine] playEffect:@"CrashSound.wav"];
}
}
}
请帮忙。