2011-08-15 17 views
1

嗨矩形的重複這個問題,但我不能找出我做錯了..我在cocos2d一個小白......讓周圍的精靈在cocos2d對不起

這裏是我的頭文件:

#import "cocos2d.h" 
#import "Mice.h" 
// HelloWorld Layer 
@interface PlayScreen : CCLayerColor 
{ 

enter code here 
Mice *mice ; 
CGRect screenSize; 

CCSprite *background ; 
CCSprite *objectsBoundry; 
CCSprite *scoreBoundry ; 

} 

//返回包含HelloWorld作爲獨生子女

+(id) scene; 
@property (retain,nonatomic)Mice *mice; 
@property (retain,nonatomic)CCSprite *background; 
@property (retain,nonatomic)CCSprite *objectsBoundary; 
@property (retain,nonatomic)CCSprite *scoreBoundary; 


- (void)rotateEnemy:(Mice *) pSprite; 
- (CGRect)rectMake ; 
@end 

場景,這是我實現文件

-(id)init{ 
if((self=[super init])) { 
    mice = [Mice spriteWithFile:@"mice.png" ]; 
    CGRect * micerec = [mice rectMake];//gives an error here that mice may not respond //to method rectMake 

} 
    return self; 
} 

-(CGRect)rectMake { 

    CGRect aRect = CGRectMake((self.position.x-self.contentSize.width/2), 
          (self.position.y-self.contentSize.height/2), 
          self.contentSize.width,self.contentSize.height); 


return aRect; 
} 

不明白什麼是錯..感謝您的幫助

回答

2

你rectMake方法是不是你的鼠標類中。那是你的問題。此處還有一個更好的從CCMenuItem修改的矩形方法:

-(CGRect) rect 
{ 
    return CGRectMake(position.x - contentSize.width*anchorPoint.x, 
         position.y - contentSize.height*anchorPoint.y, 
         contentSize.width, contentSize.height); 
} 

確保CCSprite.contentSize不爲空。發生這種情況的示例:您使用CCSprite,但添加實際內容顯示在該CCSprite的子項中。

+0

對不起哥們...還是同樣的錯誤不能訪問的方法:( –

+0

@Gaurav_soni我現在看到問題了,我已經更新了我的答案。 –