Answer the question
In order to leave comments, you need to log in
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
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
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:;
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 questionAsk a Question
731 491 924 answers to any question