我最近開始使用Sprite Kit,現在我剛剛打開了一個新的Sprite Kit項目,並刪除了MyScene
類,因爲我不需要它。我然後創建了自己的SKView的子類,稱爲PhyscisScene
現在,當我已經做到了這一點,並在ViewController.m
取代了代碼,我得到線24在ViewController.m
此錯誤:No known class method for selector 'sceneWithSize:'
下面是我的所有類文件我一直希望你改能告訴我怎麼回事:奇怪的錯誤「沒有已知的類選擇器的方法」sceneWithSize:'「
ViewController.m
#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
PhysicsScene.m
#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
PhysicsScene接口(可能位於PhysicsScene.h中)是否包含像+(id)sceneWithSize:(CGSize)大小的方法; ?聽起來好像沒有。 – danh
@danh否,但我爲sprite工具包創建的另一個項目不包含它,但編譯時沒有任何編譯錯誤也不應該手動輸入sceneWithSize,因爲它已經在項目創建時已經存在 – Mutch95