Posts

Post not yet marked as solved
2 Replies
1.6k Views
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....
Posted
by chps67.
Last updated
.
Post not yet marked as solved
0 Replies
616 Views
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];     } }
Posted
by chps67.
Last updated
.
Post not yet marked as solved
2 Replies
1.4k Views
Hi there,I'm trying to figure out what happens with my cross-platform app upon initializing and instance of AVAudioPlayer. The following code works fine in iOS (12.3.1) but crashes at runtine when trying to run initWithContentsOfURL in macOS (10.14.5) : i.e. SIGABRT with the following error: libc++abi.dylib: terminating with uncaught exception of type NSException. Any idea of what's going on ? Any suggestion or help appreciated.Best ... NSURL* soundURL = [self.soundDictionary objectForKey:self.soundPlayingRequest]; if (soundURL != nil) { NSError *error =nil; self.soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error]; soundPlayer.delegate = self; if (error.description == noErr) [self.soundPlayer play]; }
Posted
by chps67.
Last updated
.