简体   繁体   English

ios 键控存档 Sprite Kit 解码错误:SKTexture:加载图像资源时出错:“缺少 Resource.png”

[英]ios keyed archive Sprite Kit decode error: SKTexture: Error loading image resource: "Missing Resource.png"

When I archive SKLabelNodes and SKShapeNodes (I have not tried SKSpriteNotes) no problem, but when I extract the sprites from the archive i get SKTexture: Error loading image resource: "Missing Resource.png".当我存档 SKLabelNodes 和 SKShapeNodes(我没有尝试过 SKSpriteNotes)时没问题,但是当我从存档中提取精灵时,我得到 SKTexture: Error loading image resource: "Missing Resource.png"。

Here is some example code that demonstrates the problem:下面是一些演示问题的示例代码:

-(id)initWithSize:(CGSize)size {    
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */

        self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];

        SKLabelNode *const myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];

        myLabel.text = @"Hello, World!";
        myLabel.fontSize = 30;
        myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
                                       CGRectGetMidY(self.frame));

        // Archive
        NSFileManager *const fm = [NSFileManager defaultManager];
        NSURL *const dir = [fm URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
        NSURL *const archive = [dir URLByAppendingPathComponent:@"example"];
        [NSKeyedArchiver archiveRootObject:myLabel toFile:archive.path];

        // Unarchive
        SKLabelNode *const arLabel = [NSKeyedUnarchiver unarchiveObjectWithFile:archive.path];
        myLabel.position = CGPointMake(CGRectGetMidX(self.frame) + 30,
                                       CGRectGetMidY(self.frame) + 30);


        [self addChild:myLabel];
        [self addChild:arLabel];
    }
    return self;
}

Any idea what I am doing wrong?知道我做错了什么吗?

This code works for me.这段代码对我有用。 Both labels show up, no "missing resources" icon.两个标签都显示出来,没有“缺少资源”图标。

I put it in a SKScene's init as you had it above, and also ran it when the user presses a button.我把它放在 SKScene 的 init 中,就像上面一样,并且在用户按下按钮时运行它。 Tested on iPhone Retina Simulator, both regular and 64-bit and both iOS 7.0 and 7.1 as well as iPod Touch 5G with iOS 7.1.在 iPhone Retina Simulator(普通版和 64 位)、iOS 7.0 和 7.1 以及 iPod Touch 5G 和 iOS 7.1 上测试。

I'd suggest putting this code in a newly created Sprite Kit project to verify it is working for you as well.我建议将此代码放在新创建的 Sprite Kit 项目中,以验证它是否也适用于您。 If it is, the problem must be with your project.如果是,则问题一定出在您的项目上。 If it's still not working even in a new project, then ... I don't know.如果即使在新项目中它仍然无法正常工作,那么......我不知道。 Perhaps you might want to update Xcode if you aren't using Xcode 5.1.如果您不使用 Xcode 5.1,也许您可​​能想要更新 Xcode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM