声音和动画的例子

来源:互联网 发布:unity3d 开发web 编辑:程序博客网 时间:2024/06/05 05:48

-(void)playSound:(NSString*)soundAct{

NSString *path = [NSStringstringWithFormat:@"%@%@",

  [[NSBundlemainBundle] resourcePath],

  soundAct];

NSLog(@"%@\n", path);

SystemSoundID soundID;

NSURL *filePath = [NSURLfileURLWithPath:path isDirectory:NO];

AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);

AudioServicesPlaySystemSound(soundID);

[filePath release];

}


- (IBAction)jump:(id)sender{

if(RYU.center.y >216){

RYU.animationImages = [NSArrayarrayWithObjects

  [UIImageimageNamed:@"jump1.png"],

  [UIImageimageNamed:@"jump2.png"],

  [UIImageimageNamed:@"jump2.png"],

  [UIImageimageNamed:@"jump1.png"],

 nil];

RYU.animationDuration =1.0;

RYU.animationRepeatCount =1;

[RYUstartAnimating];

[UIImageViewbeginAnimations:@"jump"context:RYU];

[UIImageViewsetAnimationDuration:1.0];

RYU.center=CGPointMake(RYU.center.x,RYU.center.y-50);

    RYU.center=CGPointMake(RYU.center.x,RYU.center.y+50);

[UIImageViewcommitAnimations];

        soundFile = [NSStringstringWithFormat:@"/sound.caf"];

    [selfplaySound: soundFile];

}

}