将我的动画添加到我的可玩角色

时间:2014-12-14 09:12:03

标签: ios animation view

好的,以下代码在我的角色.m文件中,并且是我想在游戏开始时运行的动画的代码,以便您可以通过4个图像播放动画角色。

-(void) Animate {

    UIImage* img1 = [UIImage imageNamed:@"Obstacle.png"];
    UIImage* img2 = [UIImage imageNamed:@"Obstacle02.png"];
    UIImage* img3 = [UIImage imageNamed:@"Obstacle03.png"];
    UIImage* img4 = [UIImage imageNamed:@"Obstacle04.png"];

    NSArray *animateArray = [NSArray arrayWithObjects:img1,img2,img3,img4, nil];

    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 160, 160)];

    self.imageView.animationImages = animateArray;

    self.imageView.animationDuration = 0.5;

    [self.imageView startAnimating];

    self.imageView.animationRepeatCount = 0;

    [self.view addSubview:self.imageView];

}

但我对如何将这个序列添加到我的实际角色视图(可玩角色)感到茫然。我已经去了,你可以看到[self.view addSubview:self.imageView];但是这个代码是在之前的问题中提供给我的,我不明白。如果有人可以提供帮助,那就太棒了。

1 个答案:

答案 0 :(得分:0)

最后一行将图像视图添加到UIView子类。如果这个类是你角色的视图,那么当你调用这个函数时,你会看到动画位于给定的帧。