2014-01-27 38 views
-1

我最近開始使用Sprite Kit,現在我剛剛打開了一個新的Sprite Kit項目,並刪除了MyScene類,因爲我不需要它。我然後創建了自己的SKView的子類,稱爲PhyscisScene現在,當我已經做到了這一點,並在ViewController.m取代了代碼,我得到線24ViewController.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 
+0

PhysicsScene接口(可能位於PhysicsScene.h中)是否包含像+(id)sceneWithSize:(CGSize)大小的方法; ?聽起來好像沒有。 – danh

+0

@danh否,但我爲sprite工具包創建的另一個項目不包含它,但編譯時沒有任何編譯錯誤也不應該手動輸入sceneWithSize,因爲它已經在項目創建時已經存在 – Mutch95

回答

3

PhysicsSceneSKView的子類。它看起來像PhysicsScene應該是SKScene的一個子類。解決方法是將PhysicsScene轉換爲SKScene的子類,因爲這看起來就像您要使用它的。

1

望着文檔,sceneW ithSize是SKScene的類方法,而不是SKView。

相關問題