Reputation: 910
I am trying to create a screensaver with a sprite kit scene in Swift. When I first made the project, and before I added any SpriteKit code, I ran into the issue where the Screensaver built but only displayed "You cannot use the screensaver X with this version of OS X".
This was solved, or so I thought, by adding, to the build settings:
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
Which seemed to do the trick. I thought this problem was behind me, but now that I have added a very simple SpriteKit scene (just displaying a BG color) the message is back. Can anyone confirm that a Screensaver CAN use SpriteKit, and if so, any ideas on how to make it work?
Upvotes: 2
Views: 446
Reputation: 16827
[Edit]
Turns out, with using ScreenSaverView
in 100% swift code, it does not like any swift objects outside of the ScreenSaverView swift file. If you keep your code inside of the file, then you will not get this error.
--Old Stuff--
You should be able to add the SKView as a child to the ScreenSaverView, then do your sprite kit work in this SKView, other than that, everything should work as expected as long as you are on a version of OSX that supports Sprite Kit, if you could tell me the version you are testing on, I will run it in on mine.
Perhaps this is your problem, you are running on something < 10.9.
Source: Sprite Kit OSX not loading start up code for spaceship
Code that works:
#import "screenSaverTestView.h"
#import <SpriteKit/SpriteKit.h>
#import "screenSaverTest-Swift.h"
@implementation screenSaverTestView
- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
[self setAnimationTimeInterval:1/30.0];
MyView *view = [[MyView alloc] init];
[self addSubview:view];
}
return self;
}
- (void)startAnimation
{
[super startAnimation];
}
- (void)stopAnimation
{
[super stopAnimation];
}
- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
}
- (void)animateOneFrame
{
return;
}
- (BOOL)hasConfigureSheet
{
return NO;
}
- (NSWindow*)configureSheet
{
return nil;
}
@end
====SWIFT=====
import Foundation
import SpriteKit
class MyView : SKView
{
override func viewWillMoveToSuperview(newSuperview: NSView?) {
self.presentScene(SKScene(size: self.frame.size));
}
}
Upvotes: 1