我是新来的cocos2d。在我的游戏中,不同颜色的气球从底部随机产生,并且存在与类似(两个或更多)精灵/气球相关的特定声音点击这不起作用。例如。与气球图像red.png关联red.wav和blue.png,blue.wav在那里等等。再次当红色气球来临时,red.wav与它相关联。以下是我使用的音响协会代码: -如何获得两个或更多(相同)精灵点击类似的声音?
(无效)selectSpriteForTouch:(CGPoint)touchLocation { 为(CCSprite *在目标精灵) {
if (CGRectContainsPoint([sprite boundingBox], touchLocation)) { //NSLog(@"sprite was touched"); NSLog(@"strGetImgName%@",strGetImgName); [targets removeObject:sprite]; if ([strGetImgName isEqualToString:@"balloon1"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button1.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon2"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button2.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon3"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button3.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon4"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button4.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon5"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button5.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon6"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button6.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon7"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button7.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon8"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button8.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon9"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button9.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else if ([strGetImgName isEqualToString:@"balloon10"]) { [[SimpleAudioEngine sharedEngine] playEffect:@"button10.wav"]; [[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f]; } else { NSLog(@"nothing remaining"); } [self balloonBlastAnimation:sprite]; [sprite.parent removeChild:sprite cleanup:YES]; break; }
} }
我只需要在两个或更多类似的气球点击上生成独特的声音。实际上不需要创建字符串和全部。简单地将气球与标签关联即可。 –
有很多方法可以编码相同的输出。上述所有方法都同样好。然而,自己找到解决方案总是更好...... !! – samfisher
这实际上是我做这件事的方式,因为枚举只是给定值0的列表 - 列表的结尾。很高兴你能解决这个问题。 – Bongeh