Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在游戏加载后延迟图像动画_Ios_Animation - Fatal编程技术网

Ios 如何在游戏加载后延迟图像动画

Ios 如何在游戏加载后延迟图像动画,ios,animation,Ios,Animation,我需要找到一个选项来延迟这个对象cloudDrop2图像上的动画。每次我加载游戏时,cloudDrop2图像都显示正在下降。我想在加载游戏后将动画延迟5秒。5秒钟后,图像显示下降。我使用的是Xcode 5 有什么帮助或建议吗 下面是我正在使用的代码: 在.m文件上 -(void)cloudDrop2Code{ // cloudDrop2 Images Animation cloudDrop2.animationImages = [NSArray arrayWithObjects:

我需要找到一个选项来延迟这个对象cloudDrop2图像上的动画。每次我加载游戏时,cloudDrop2图像都显示正在下降。我想在加载游戏后将动画延迟5秒。5秒钟后,图像显示下降。我使用的是Xcode 5

有什么帮助或建议吗

下面是我正在使用的代码:

在.m文件上

-(void)cloudDrop2Code{

// cloudDrop2 Images Animation
cloudDrop2.animationImages = [NSArray arrayWithObjects:
                              [UIImage imageNamed:@"cloudDrop2.png"],
                              [UIImage imageNamed:@"cloudDrop1.png"],
                              [UIImage imageNamed:@"cloudDrop2.png"],
                              [UIImage imageNamed:@"cloudDrop1.png"],
                              [UIImage imageNamed:@"cloudDrop2.png"],
                              [UIImage imageNamed:@"cloudDrop1.png"],
                              [UIImage imageNamed:@"cloudDrop2.png"],
                              [UIImage imageNamed:@"cloudDrop1.png"],nil];

[cloudDrop2 setAnimationRepeatCount:1];
cloudDrop2.animationDuration = 0.1;
[cloudDrop2 startAnimating];

// Drop Cloud Ramdom Position

cloudDrop2.center = CGPointMake(cloudDrop2.center.x, cloudDrop2.center.y +2.1);
if (cloudDrop2.center.y > 590){

    RamdomPosition = arc4random() %266;
    RamdomPosition = RamdomPosition +54;

    cloudDrop2.center = CGPointMake(RamdomPosition, -40);
    dropCloudUsed = NO;


    // Time to Drop Cloud Down Again
    [[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:7.0]];

}
}

然后在viewDidLoad方法中:

欢迎来到SO

我没有看到任何负责加载游戏部件的代码。你可能应该把它贴出来,以便更容易回答你的问题

由于没有看到代码的任何其他部分,我建议您在游戏加载完成时使用NSNotification来提醒您。收到通知后,可以开始动画序列

你可以在报纸上读到。如果你需要帮助或指点,不要害怕问

要使用5秒的计时器延迟来启动动画,可以使用以下方法:

[NSTimer scheduledTimerWithTimeInterval:5.0
  target:self
selector:@selector(targetMethod:)
userInfo:nil
 repeats:NO];

其中targetMethod:是包含动画的方法的名称。

在单独的方法中创建计时器

- (void)startGameAnimation
{
  // cloudDrop2 Down Movement Speed
TMcloudDrop2 = [NSTimer scheduledTimerWithTimeInterval:0.03 
                        target:self 
                        selector:@selector(cloudDrop2Code)
                        userInfo:nil 
                        repeats:YES];
}
然后在viewDidLoad中延迟调用此方法

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self performSelector:@selector(startGameAnimation) withObject:nil afterDelay:5];
}

-iAction可能链接到屏幕上的一个按钮,是点击按钮时运行的代码。viewDidLoad可能是游戏加载的第一部分开始的地方。如果你正在学习,我建议你尝试一下。开始在viewDidLoad中添加NSNotification,看看会发生什么。如果你没有得到你想要的结果,那么试试IBAction。@HEMAN85-我已经更新了答案,加入了一个5秒计时器。这就像一个符咒,谢谢你Mustafa Ahmed,现在我的游戏看起来也很干净。谢谢你的时间。你想运行什么代码?!cloudDrop2Code方法已在您将计时器设置为重复时每0.03秒运行一次。通常,您可以将另一个计时器的时间间隔设置为18。[NSTimer scheduledTimerWithTimeInterval:18目标:自选择器:@selectorcloudDrop2Code用户信息:无重复:是];这很奇怪,就像需要等待所有其他动画再次出现一样。所有其他动画都会在云层之后落下,但随后会显示所有图像同时落下。有什么想法或建议吗?很抱歉回复晚了。今天我将试用你的代码并向你发送我的反馈。如果你有一个样本项目,做什么你有问题,这将节省我的时间。
- (void)viewDidLoad
{
  [super viewDidLoad];
  [self performSelector:@selector(startGameAnimation) withObject:nil afterDelay:5];
}