A
A
Alexander Zarochintsev2014-03-17 17:16:52
Objective-C
Alexander Zarochintsev, 2014-03-17 17:16:52

IOS - how to implement game animation in the background?

Good time of the day! I was given the task of implementing the game, if the implementation of the game does not raise questions, then the animation in the game is a continuous issue for me. Actually, the task: during the game, in the background, play an animation lasting 16 seconds, how can this be done? What animation format should be? What do you need for game animation in iOS?
Until that time, I was not engaged in animation at all, in other words, I don’t understand what needs to be done in general in order to implement it. I will be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Morozov, 2014-03-17
@Kovalskiy

navskynd two options immediately come to mind:
1. implement your own view that will display a list of pictures in turn and at the same time not load them all at once, but load the necessary ones when necessary, and unload the viewed ones from memory
2. collect it into a vidos and run it on in the background
, I would do the first option, it is more flexible. in the first option, nothing needs to be collected additionally if the number of frames and / or the frames themselves change

//как-то так должен выглядеть MyImagesView.m файл

@interface MyImagesView ()

@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, assign) int currentImage;
@property (nonatomic, assign) int totalImages;

@end

@implementation

/*
 * этот метод надо вызывать в таймере. обязательно в Main Thread
 */
- (void)showNextImage
{
  assert([NSThread isMainThread] == YES);
  
  self.currentImage ++;
  if (self.currentImage == self.totalImages)
  {
    // что бы отображать картинки циклически
    self.currentImage = 0;
  }
  
  UIImageView *newImageView = ;
  
  [self.imageView removeFromSuperview]; // убираем прирыдущий кадр из view-хи (затираем сильную ссылку номер 1)
  self.imageView = nil; // убираем сильную ссылку номер два (тут UIImageView должна выгрузиться из памяти, а с ней и UIImage)
  
  [self addSubview:newImageView]; // закидываем новый кадр во view-ху (создаём сильную ссылку номер 1)
  self.imageView = newImageView; // сохраняем ссылку на новый кадр что бы иметь в следующем вызове метода showNextImage ссылку на предыдущий кадр  (создаём сильную ссылку номер 2)
}

@end

UPD:
try replacing:
newImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image_name%i.png", self.currentImage]];
on the:
NSString *imageName = [NSString stringWithFormat:@"image_name%i", self.currentImage];
newImageView.image = [UIImage imageWithContentsOfFile:;

K
kocherovets, 2014-03-17
@kocherovets

Look for some implementation of frame-by-frame animation on UIKit if you are interested in hand-drawn animation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question