我下面的代码从像 (Duck1_1,Duck1_2,Duck1_3,etc) 这样的 plist 中的文件查找中的图像名称创建纹理,它循环遍历它们,然后将它们添加到可变数组中。然后使用可变数组对存储的纹理进行动画处理,并使用 SKAction 进行播放。这对动画效果很好,直到播放 30-40 然后它崩溃并说打开了太多文件并且无法再打开文件。关于如何阻止这种情况发生的任何想法?谢谢
//loadPlistForAnimationWithNames function
NSMutableArray *animationToReturn = [NSMutableArray array];
for(NSString *frameNumber in animationFrameNumbers) {
NSString *frameName = [NSString stringWithFormat:@"%@%@.png",animationFramePrefix,frameNumber];
if(frameName!=nil)
[animationToReturn addObject:[SKTexture textureWithImageNamed:frameName]];
}
SKAction *action=nil;
action=[SKAction animateWithTextures:animationToReturn timePerFrame:animationDelay resize:NO restore:NO];
SKAction *repeatAction=nil;
repeatAction = [SKAction repeatAction:action count:1];
[animationToReturn removeAllObjects];
action=nil;
animationFrameNumbers=nil;
return repeatAction;
//Call to loadPlistForAnimationWithNames and run animation
SKAction *action=[animalObject loadPlistForAnimationWithNames:@"duckAnim1" andClassName:NSStringFromClass([self class])];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Duck1_1"];
sprite.position=CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
sprite.size=self.frame.size;
[sprite setZPosition:3];
[self addChild:sprite];
[sprite runAction:action];
这是我在崩溃时遇到的 Xcode 错误: ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed '/private/var/mobile/Containers/Bundle/Application/782E98C3-0452-43EF-BF4D-401773D5FDCD/WildNoizesLite.app/Duck1_1.png ' 错误 = 24 (打开的文件太多)
Backtrace: * thread #1: tid = 0x301c4, 0x00000001944ab270 libsystem_kernel.dylib __pthread_kill __pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001944ab270 libsystem_kernel.dylib
+ 8 frame #1: 0x0000000194549170 libsystem_pthread.dylib pthread_kill + 112
frame #2: 0x0000000194422b18 libsystem_c.dylib
abort + 112 frame #3: 0x00000001934b5418 libc++abi.dylib abort_message + 116
frame #4: 0x00000001934d4b8c libc++abi.dylib
default_terminate_handler() + 304 frame #5: 0x0000000193ce83c0 libobjc.A.dylib _objc_terminate() + 128
frame #6: 0x00000001934d1bb4 libc++abi.dylib
std::__terminate(void (*)()) + 16 帧 #7: 0x00000001934d173c libc++abi.dylib __cxa_rethrow + 144
frame #8: 0x0000000193ce8294 libobjc.A.dylib
objc_exception_rethrow + 44 帧 #9: 0x0000000181ef5384 CoreFoundation CFRunLoopRunSpecific + 572
frame #10: 0x000000018b94b6fc GraphicsServices
GSEventRunModal + 168 帧 #11: UIApplicationMain + 1488
* frame #12: 0x0000000100174fa0 Wild Noizes
0x0000000186af2 argc=1, argv=0x000000016fd6f9d8) + 124 at main.m:16 frame #13: 0x0000000194392a08 libdyld.dylib`start + 4