1

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 ?

1 Answers1

0

I'm pretty sure the problem is because you are still using a literal string for the playEffect parameter but your intent was to use the newly defined string variable.

Try changing:

[[SimpleAudioEngine sharedEngine] playEffect:@"Soundname"];

to this (note the lack of quotes):

[[SimpleAudioEngine sharedEngine] playEffect:Soundname];
jaket
  • 9,140
  • 2
  • 25
  • 44
  • That's actually what I did first and also that's what made the most sense but for some reason that still makes it so no sound plays at all :/ – Christian Lampman Mar 23 '15 at 03:41
  • Is it possible that I have to place NSSTring at the top of the file rather than defining it right above where the sound plays? – Christian Lampman Mar 23 '15 at 03:41
  • Then you have another problem that is not string related. First I would suggest you try playing your original Swoosh.mp3 in one of the cases in the second code example and then try playing Swoosh1.mp3 in the first code example. There could be a problem locating the file. Double check that the case of the string is exact since the device is case sensitive. Also make sure the files are properly added to the project and getting copied to the destination. – jaket Mar 23 '15 at 05:36
  • Jaket, you were spot on. I forgot to add the files to Xcode itself. Thank you!! – Christian Lampman Mar 24 '15 at 19:56