iphone - Trying to play a Random Sound using SimpleAudioEngine, no sound -
so app going produce made 1 sound upon swiping up. code 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 want there 3 sounds randomly play upon each swipe rather one. here's 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 string, replaced playeffect:@"swoosh.mp3"]; playeffect:@"soundname"];
i've tried multiple variations of soundname, none seem me working. i'm fairy new @ coding, know silly i'm missing. have ideas ?
i'm pretty sure problem because still using literal string playeffect parameter intent use newly defined string variable.
try changing:
[[simpleaudioengine sharedengine] playeffect:@"soundname"];
to (note lack of quotes):
[[simpleaudioengine sharedengine] playeffect:soundname];
Comments
Post a Comment