2012-04-24 53 views
0

嘿,我有一些代碼不斷返回錯誤信息,但我找不出什麼問題。我對Objective-C語法相當陌生,所以它可能相當簡單,但我似乎無法找到問題。該方法是CGPoint的初始化工具無效

-(void)setPlayerPosition:(CGPoint) position { 
    CGPoint tileCoord = [self tileCoordForPosition:position]; 
    int tileGid = [metaLayer tileGIDAt:tileCoord]; 
    if (tileGid) { 
     NSDictionary *properties = [tileMap propertiesForGID:tileGid]; 
     if (properties) { 
      NSString *collision = [properties valueForKey:@"Collidable"]; 
      if (collision && [collision compare:@"True"] == NSOrderedSame) { 
       return; 
      } 
      NSString *collectable = [properties valueForKey:@"Collectable"]; 
      if (collectable && [collectable compare:@"True"] == NSOrderedSame) { 
       [metaLayer removeTileAt:tileCoord]; 
       [foreground removeTileAt:tileCoord]; 
      } 
     } 
    } 
    player.position = position; 
} 

它返回錯誤無效初始化爲2號線和也說,我的課可以不迴應「tileCoordForPosition:」任何幫助,將不勝感激!

回答

0

您需要在頭文件中聲明tileCoordForPosition:,以便編譯器知道它返回的是什麼類型(在本例中爲CGPoint)。

1

我假定你是下面的文章在http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2

所以經過簡單閱讀我自己,我的猜測是,你要麼缺少所需的方法或沒有在你的類正確聲明它。

你應該有以下方法聲明和實現

- (CGPoint)tileCoordForPosition:(CGPoint)position 

它應該是在同一個班,你把它叫做自我

[self tileCoordForPosition:position] 

如果你有在實施該方法然後你的班級確保你正確地聲明瞭它。嘗試將其添加到您的.m文件的頂部像這樣

@interface YourControllerNameHere() 

- (CGPoint)tileCoordForPosition:(CGPoint)position; 

@end