Spritekit adding a sound effect

ios, objective-c, skaction, sprite-kit

Solution

Try this one :

make sure first you have put `self.userInteractionEnabled = YES;`

touches delegate method when clicked on screen:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
      // For play your wav file here
      [self runAction:[SKAction playSoundFileNamed:@"sfx.wav" waitForCompletion:NO]];

      // if you want do with touches point do here 
      for (UITouch *touch in touches) {
        CGPoint touchLocation = [touch locationInNode:self];
        //do your stuff here
      }
}

where should I store the sound file in my project?

- you have to put it in your application of document directory mean resource folder.

Problem

I'm trying to add a sound effect to a game whenever the screen is touched. I already have a touchesBegan method that moves a character, can i put the : ``` [SKAction playSoundFileNamed:@"sfx.wav" waitForCompletion:NO]; ``` into that method or do I need to make a new method. Also, where should I store the sound file in my project? Is there a certain place for it or can it just be anywhere?

Original source