简体   繁体   中英

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".

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. 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.

I'd suggest putting this code in a newly created Sprite Kit project to verify it is working for you as well. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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