我最近开始使用Sprite Kit,我刚刚开了一个新的sprite kit项目并删除了MyScene
课程,因为我不需要它。我已经创建了自己的SKView子类,名为PhyscisScene
,现在当我完成此操作并替换ViewController.m
中的代码时,我在第24行 ViewController.m
:No known class method for selector 'sceneWithSize:'
以下是我所有的班级文件我希望你能告诉我发生了什么:
#import "ViewController.h"
#import "PhysicsScene.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [PhysicsScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
@end
#import "PhysicsScene.h"
@implementation PhysicsScene
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
答案 0 :(得分:3)
PhysicsScene
是SKView
的子类。看起来PhysicsScene
应该是SKScene
的子类。解决方案是将PhysicsScene
转换为SKScene
的子类,因为这就是您想要使用它的目的。
答案 1 :(得分:1)
查看文档,sceneWithSize是SKScene的类方法,而不是SKView。