ios - Playing music from a SKAction -


i trying add background music game. have switch mute music , when tap again play music. code play music

 var backgroundmusic = skaction.playsoundfilenamed("background.wav", waitforcompletion: true)  runaction(skaction.repeatactionforever(backgroundmusic), withkey: "music") 

i know waitforcompletion should set false stop music when tap switch. when have set false music doesn't play static sound.

self.removeactionforkey("music") 

that code used stop music. wonder if can mute music until track finished or there way play music forever in spritekit.

i recommend using objectal instead of spritekit background music. or here simple method use background music, borrowed skutils:

-(avaudioplayer*)setupsound:(nsstring*)file volume:(float)volume{     nserror *error;     nsurl *url = [[nsbundle mainbundle] urlforresource:file withextension:nil];     avaudioplayer *s = [[avaudioplayer alloc] initwithcontentsofurl:url error:&error];     s.numberofloops = -1;     s.volume = volume;     [s preparetoplay];     return s; } 

then call follows:

... avaudioplayer *bgplayer = [self setupsound:@"background.wav" volume:1.0]; ... [bgplayer play]; ... [bgplayer pause]; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -