伙计我需要知道如何在游戏加载后显示下降7秒的图像?
这是我目前的代码:
在.h
档案
IBOutlet UIImageView *CloudDrop;
NSTimer *timer;
-(void)CloudDropCode;
在.m
档案
-(void)CloudDropCode{
// Drop Cloud Images Animation
CloudDrop.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"CloudDrop2.png"],
[UIImage imageNamed:@"CloudDrop.png"],
[UIImage imageNamed:@"CloudDrop2.png"],
[UIImage imageNamed:@"CloudDrop.png"],
[UIImage imageNamed:@"CloudDrop2.png"],
[UIImage imageNamed:@"CloudDrop.png"],
[UIImage imageNamed:@"CloudDrop2.png"],
[UIImage imageNamed:@"CloudDrop.png"],nil];
[CloudDrop setAnimationRepeatCount:1];
CloudDrop.animationDuration = 0.1;
[CloudDrop startAnimating];
// Drop Cloud Ramdom Position
CloudDrop.center = CGPointMake(CloudDrop.center.x, CloudDrop.center.y +2);
if (CloudDrop.center.y > 590){
ramdomPosition = arc4random() %266;
ramdomPosition = ramdomPosition +54;
CloudDrop.center = CGPointMake(ramdomPosition, -40);
dropCloudUsed = NO;
// Time to Drop Cloud Down Again
[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:7.0]];
CloudDrop.hidden = NO;
}
}
这是viewDidLoad
:
- (void)viewDidLoad
timer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(CloudDropCode)userInfo:nil repeats:YES];
现在,当游戏加载时,图像会下降。我试图在游戏加载10秒后跌落图像。任何想法或建议?感谢
答案 0 :(得分:0)
定义变量:
CloudDrop.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"CloudDrop2.png"],
[UIImage imageNamed:@"CloudDrop.png"],nil];
NSUInteger currentIndex = 0;
重复下一个方法7次
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//Update there. get next image by index and realize animation
} completion:^(BOOL finished) {
if (currentIndex == 0)
currentIndex++;
else
currentIndex = 0;
}];
实现备用函数调用以自行完成。