所以最初我打算制作的应用程序只在刷完时发出一个声音。代码是
[[SimpleAudioEngine sharedEngine] playEffect:@"Swoosh.mp3"];
CCMoveTo *moveto=[CCMoveTo actionWithDuration:0.50 position:ccp(currentSkewed.position.x, [UIScreen mainScreen].bounds.size.height+300)];
CCScaleTo *scalto=[CCScaleTo actionWithDuration:0.30 scale:0.5];
CCSequence *seq=[CCSequence actionOne:moveto two:[CCCallFuncN actionWithTarget:self selector:@selector(RemoveSprite:)]];
[currentSkewed runAction:seq];
[currentSkewed runAction:scalto];
[skewdArray removeObject:currentSkewed];
currentSkewed=nil;
我决定我想要在每次滑动时随机播放三种声音,而不仅仅是一种。所以这就是我所做的。
NSString *Soundname;
int randSound = arc4random() % 3;
switch (randSound) {
case 0:
Soundname = @"Swoosh1.mp3";
break;
case 1:
Soundname = @"Swoosh2.mp3";
break;
case 2:
Soundname = @"Swoosh3.mp3";
break;
}
[[SimpleAudioEngine sharedEngine] playEffect:@"Soundname"];
CCMoveTo *moveto=[CCMoveTo actionWithDuration:0.50 position:ccp(currentSkewed.position.x, [UIScreen mainScreen].bounds.size.height+300)];
CCScaleTo *scalto=[CCScaleTo actionWithDuration:0.30 scale:0.5];
CCSequence *seq=[CCSequence actionOne:moveto two:[CCCallFuncN actionWithTarget:self selector:@selector(RemoveSprite:)]];
[currentSkewed runAction:seq];
[currentSkewed runAction:scalto];
[skewdArray removeObject:currentSkewed];
currentSkewed=nil;
我制作了弦乐,然后取代了playEffect:@" Swoosh.mp3"]; playEffect:@" Soundname"];
我尝试过Soundname的多种变体,但似乎没有人在工作。我是一位擅长编码的童话,我知道这是我所遗忘的愚蠢行为。有没有人有任何想法?
答案 0 :(得分:0)
我很确定问题是因为你仍在为playEffect参数使用文字字符串,但你的目的是使用新定义的字符串变量。
尝试更改:
[[SimpleAudioEngine sharedEngine] playEffect:@"Soundname"];
到此(注意缺少引号):
[[SimpleAudioEngine sharedEngine] playEffect:Soundname];