2

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?

Howard Lovatt
  • 968
  • 1
  • 8
  • 15

1 Answers1

2

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thanks for this comment, really helpful. My Xcode was unto date, but I hadn't got the Simulator for 7.0 downloaded. Seeing that you tested on various devices including ones running 7.0 I tried downloading this Simulator. Hey presto, it works on 7.0 but not 7.1 for me. So I guess the answer is that it is a bug in the 7.1 Simulator. Thanks again, really helpful. – Howard Lovatt Mar 31 '14 at 02:49
  • also works on 7.1 for me, both Simulator and device. Try your code in a newly created project to see if it makes any difference – CodeSmile Mar 31 '14 at 06:49
  • Yes have tried a newly created project, no difference only works on 7.0 – Howard Lovatt Apr 01 '14 at 23:06
  • I am having this same problem (with an `SKLabelNode`) in my project, and, furthermore, I can reproduce the problem on a new `SpriteKit` project (just pasting the above code into the generated `MyScene initWithSize`). I'm using Xcode Version 5.1.1 (5B1008). Also, I've got the same simulator behavior as @HowardLovatt: I can avoid the error if I have a deployment target of 7.0 and run on the 7.0 simulator; all other combinations cause the error. – Karl Voskuil May 15 '14 at 15:41
  • any update to this? i have the same problem, unarchival works in iOS 8, busted textures in 7.1. I'm using this on SKSpriteNode – Matt Fiocca Dec 03 '14 at 23:00