vendredi 20 mars 2015

Trying to play a Random Sound using SimpleAudioEngine, no sound

So initially the app I was going to produce only made one sound upon swiping up. The code for that was



[[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;


I decided I want there to be three sounds that randomly play upon each swipe rather than just one. So here's what I did.



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;


I made the string, then replaced playEffect:@"Swoosh.mp3"]; with playEffect:@"Soundname"];


I've tried multiple variations of Soundname, none seem to me working. I'm fairy new at coding, I know this is something silly that i'm missing. Does anybody have any ideas ?


Aucun commentaire:

Enregistrer un commentaire