Post

Replies

Boosts

Views

Activity

.sks file edited and saved by my app's built-in editor do not display properly in Xcode's editor
Hi all, I'm trying to figure out which are the good bases for adding a built-in level editor to a game so that levels can be contributed by players in the form of SKScene objects (not subclassed) that are saved in .sks files and that could be directly imported into my Xcode project. Using NSKeyedArchiver, the SKScene levels can be appropriately saved and re-opened in the game's editor, but when opening them in the Xcode's scene editor I get weird display of the SKSpriteNodes. They are presented with the right size at the right place but the textures look much enlarged and randomly shifted in the sprite's frame. I tried to force the sprite's xScale and yScale to 1.0 prior to saving as well as many other size inspection, 'centerRect' enforcement, sprite re-building from the appropriate images and the result is still the same. The only way I found to fix this issue is to reload manually each sprite in the Xcode's editor by re-typing the texture's name. if anyone has an idea of what's going on, help would be appreciated Best Here are my opening and saving functions from the game's view controller (void) openSceneFile {     SKScene* theScene = nil;     NSOpenPanel* theOpenPanel = [NSOpenPanel openPanel];     NSURL * sceneURL;     NSArray* allowedType = [NSArray arrayWithObject:@"sks"];   [theOpenPanel setAllowedFileTypes:allowedType];     if ([theOpenPanel runModal] == NSModalResponseOK) {         sceneURL = [theOpenPanel URL];         NSData* sceneData = [NSData dataWithContentsOfURL:sceneURL];         NSError* err;         theScene = [NSKeyedUnarchiver unarchivedObjectOfClass:[SKScene class] fromData:sceneData error: &err];     }     GameView *skView = (GameView *)self.view;     [skView presentScene:theScene];  /* Side effect = presentation changes the scene's size to the skView's size ! */ } (void) saveSceneFile {     SKView* skView = (SKView*)self.view;     SKScene* theScene =  skView.scene;     CGSize curSize = theScene.size;     CGSize reqSize = NSMakeSize(640,480);     if (! NSEqualSizes(reqSize, curSize))         theScene.size = reqSize;         NSURL * sceneURL;     NSArray* allowedType = [NSArray arrayWithObject:@"sks"];     NSSavePanel* theSavePanel = [NSSavePanel savePanel];     [theSavePanel setAllowedFileTypes:allowedType];     [theSavePanel setTitle:@"Save Scene"];     [theSavePanel setPrompt:@"Save the current scene"];     if ([theSavePanel runModal] == NSModalResponseOK) {         sceneURL = [theSavePanel URL];         NSError* err;         NSData* sceneData = [NSKeyedArchiver archivedDataWithRootObject:theScene requiringSecureCoding:YES error:&err];         [sceneData writeToURL:sceneURL atomically:YES];     } }
0
0
712
Aug ’20
Failure to unarchive a sprite kit particle file
Hi all,I'm having trouble in trying to access the content of a sprite kit particle file in a way that conforms with the recent deprecation of several functions in NSKeyedArchiver.Briefly, my project contains a file named "ParticleSmoke.sks", which I used to access easily with the following lines of code: NSString *smokePath = [[NSBundle mainBundle] pathForResource:@"ParticleSmoke" ofType:@"sks"]; SKEmitterNode* smoke = [NSKeyedUnarchiver unarchiveObjectWithFile:smokePath];now that the unarchiving function has been deprecated, I fail to use the (poorly documented) unarchivedObjectOfClass function. Especially, the code below returns nil. NSString *smokePath = [[NSBundle mainBundle] pathForResource:@"ParticleSmoke" ofType:@"sks"]; NSData* smokeData = [NSData dataWithContentsOfFile:smokePath]; NSError* error=nil; Class cls = [SKEmitterNode class]; SKEmitterNode* smoke = (SKEmitterNode*)[NSKeyedUnarchiver unarchivedObjectOfClass:cls fromData:smokeData error:&error];Unexpectedly, the content of "error" (code 4864) was@"NSDebugDescription" : @"value for key 'NS.objects' was of unexpected class 'NSColor'. Allowed classes are '{(\n SKKeyframeSequence,\n NSArray,\n NSNumber,\n NSMutableArray\n)}'."Has anyone an idea to fix this issue?Thanks for your help....
2
0
1.8k
Sep ’19