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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With