Friday, 15 July 2011

ios - Playing music from a SKAction -


I am trying to add background music to my game. I have a switch that will mute the music and when you tap it again it will play the music. This is the code to play music

  var background music = SKAction.playSoundFileNamed ("Background. Wave", Wait End: True) Run Action (SKAction.repeatActionForever (backgroundMusic), withKey: Music ")  

I know that waitForCompletion should be set to false to stop the music when you tap the switch, but when I set it to false then the music It does not play, it's just like steady sound.

  self.removeActionForKey ("music")  

This music I used to stop music was a surprise to me if you were to finish the track You can mute the music or there is always another way to play music in the Spritekit.

I recommend using background instead of spritekit for music. Or here is a simple method that I use for background music, taken from:

  - (AviPlayer) * Setup: Sound: (NSString *) File volume: (Float) volume {NSError * error; NSURL * url = [[NSBundle Main Bundle] URLForResource: Extension with File: Zero]; AviPlayer Player * s = [[Avidio Player Alok] initWithContentsOfURL: url Error: & amp; Error]; S.numberOfLoops = -1; S.volume = Quantity; [STTopple]; Return s; }  

Then you say it like this:

  ... aviapplier * bgplayer = [auto-setupSound: @ "background noise" section: 1.0 ]; ... [BGPlayer Play]; ... [Bijipple pauses];  

No comments:

Post a Comment