ios - Adding a sound effect to a jump -
i want add sound effect jump action when character jumps. sounds simple cannot it, i've tried far..
in header file character have:
systemsoundid jump; - (void)playsound:(nsstring *)jump1 :(nsstring *) mp3;
in implementation file have:
- (void)playsound :(nsstring *)jump1 :(nsstring *) mp3{ systemsoundid audioeffect; nsstring *path = [[nsbundle mainbundle] pathforresource : jump1 oftype :mp3]; if ([[nsfilemanager defaultmanager] fileexistsatpath : path]) { nsurl *pathurl = [nsurl fileurlwithpath: path]; audioservicescreatesystemsoundid((__bridge cfurlref) pathurl, &audioeffect); audioservicesplaysystemsound(audioeffect); } else { nslog(@"error , file not found aye: %@", path); } }
also inside function jump have:
[self playsound:@"jump" :@"mp3"];
please excuse inexperience had go @ great feature game, if tell me doing wrong or different , better way works great thanks!
add method in class , whenever want play sound call method using [self playsound], jump.mp3 should in bundle, , remember 1 thing more don't forget add audiotoolbox framework.
-(void) playsound { nsstring *soundpath = [[nsbundle mainbundle] pathforresource:@"jump" oftype:@"mp3"]; systemsoundid soundid; audioservicescreatesystemsoundid((__bridge cfurlref)[nsurl fileurlwithpath: soundpath], &soundid); audioservicesplaysystemsound (soundid); }
Comments
Post a Comment