我正在尝试设置一个简单的Sprite Kit设置。 我正在做的就是从'空应用程序'重新创建默认的xCode模板'Sprite Kit Game'。
它一直在 skView.showsFPS = YES; 行崩溃。哪个我无法解释。你能?谢谢!
一些代码:
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MenuController *menuController = [[MenuController alloc] init];
self.window.rootViewController = menuController;
[self.window makeKeyAndVisible];
return YES;
}
MenuController.m
- (void)viewDidLoad
{
[super viewDidLoad];
SKView *skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
MultiplayerView *gameView = [MultiplayerView sceneWithSize:skView.bounds.size];
gameView.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:gameView];
}
当我启动它时,会发生以下错误:
2013-11-10 13:08:01.605 ByS[9419:70b] -[UIView setShowsFPS:]: unrecognized selector sent to instance 0x10c00bc60
2013-11-10 13:08:01.608 ByS[9419:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setShowsFPS:]: unrecognized selector sent to instance 0x10c00bc60'
答案 0 :(得分:25)
在界面构建器中,将窗口视图的类更改为SKView
。将UIView
打包到SKView
中除非先前通过投放UIView
获得SKView
,否则将无法执行任何操作。
答案 1 :(得分:5)
从单视图或空应用程序开始,与通常的SpriteKit模板相比,我遇到了同样的问题。当我添加一些我发现覆盖loadView方法的代码时,我工作了。尝试将它放在ViewDidLoad的视图控制器上方。
- (void)loadView {
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
SKView *skView = [[SKView alloc] initWithFrame:applicationFrame];
self.view = skView;
}
.h文件是通常的UIViewController。并且在链接框架后记住#import!:
@interface CharacterViewController : UIViewController
因此完整的.m代码将是:
@implementation CharacterViewController
- (void)loadView {
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
SKView *skView = [[SKView alloc] initWithFrame:applicationFrame];
self.view = skView;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"CharacterViewController viewDidLoad");
// Do any additional setup after loading the view.
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
CharacterScene *character = [[CharacterScene alloc]initWithSize:CGSizeMake(skView.bounds.size.width, skView.bounds.size.height)];
character.backgroundColor = [UIColor blueColor];
[skView presentScene:character];
}
答案 2 :(得分:1)
或者您可以在prepareForSegue:
或其他任何演示文稿
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIViewController *destinationVC = segue.destinationViewController;
SKView * skView = (SKView *)destinationVC.view;
if (![skView isKindOfClass:[SKView class]]) {
skView = [[SKView alloc] initWithFrame: skView.frame]; // self.view.bounds
destinationVC.view = skView;
}
}
答案 3 :(得分:0)
在MenuController.m中替换你的初始化
HTTP
带
SKView *skView = (SKView *) self.view;