私のゲームでは、再生ボタンが押された後、ゲーム ビュー コントローラーが表示され、後でゲームで使用するためにバックグラウンドでいくつかのアセットのプリロードが開始されます。
私の質問は、ホームボタンが押されたときにプリロードプロセスを停止する方法ですが、プリロードプロセスがまだ実行されていますか?
適切な割り当て解除のために、すべてのプリロードが完了するまで待つ必要があります...
ViewController.m
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
// preload intro sequences
dispatch_sync(concurrentQueue, ^{
[weak_self.spaceSun prepareAnimationArrays];
});
dispatch_async(concurrentQueue, ^{
[weak_self.sailor prepareAnimationArrays];
});
スペースサン、セーラー.m
- (void)prepareAnimationArrays
{
_introArray = [NSMutableArray new];
_introArray = [self.animator generateCachedImageArrayWithFilename:@"circleSun" extension:@".png" andImageCount:10];
self.isAnimationArrayCached = YES;
}
- (NSMutableArray *)generateCachedLoopedImageArrayWithFilename:(NSString *)filename
extension:
(NSString *)extension
andImageCount:
(int)count
{
_imagesArray = [[NSMutableArray alloc] init];
_fileExtension = extension;
_animationImageName = filename;
_imageCount = count;
for (int i = 0; i < _imageCount; i++)
{
NSString *tempImageName = [NSString stringWithFormat:@"%@%i", filename, i];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:tempImageName ofType:extension];
UIImage *frameImage = [self loadRetinaImageIfAvailable:imagePath];
UIGraphicsBeginImageContextWithOptions(frameImage.size, NO, [UIScreen mainScreen].scale);
CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
[frameImage drawInRect:rect];
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_imagesArray addObject:renderedImage];
_precachedImagesCount++;
if (_didPreCachePicture)
_didPreCachePicture();
if (_isDoublingFrames)
{
[_imagesArray addObject:renderedImage];
}
else if (_isTriplingFrames)
{
[_imagesArray addObject:renderedImage];
[_imagesArray addObject:renderedImage];
}
if (i == _imageCount - 1)
{
// we have 5 images
// 12345 already in array
// let's add 432
for (int j = _imageCount - 2; j > 0; j--)
{
tempImageName = [NSString stringWithFormat:@"%@%i", filename, j];
imagePath = [[NSBundle mainBundle] pathForResource:tempImageName ofType:extension];
frameImage = [self loadRetinaImageIfAvailable:imagePath];
UIGraphicsBeginImageContextWithOptions(frameImage.size, NO, [UIScreen mainScreen].scale);
rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
[frameImage drawInRect:rect];
renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_imagesArray addObject:renderedImage];
_precachedImagesCount++;
if (_didPreCachePicture)
_didPreCachePicture();
if (_isDoublingFrames)
{
[_imagesArray addObject:renderedImage];
}
else if (_isTriplingFrames)
{
[_imagesArray addObject:renderedImage];
[_imagesArray addObject:renderedImage];
}
}
}
}
return _imagesArray;
}