很抱歉重复这个问题,但我无法弄清楚我做错了什么..我是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;
}
不要弄错了...感谢您的帮助
答案 0 :(得分:2)
您的rectMake方法不在您的Mice类中。那是你的问题。这里还有一个从CCMenuItem修改的更好的rect方法:
-(CGRect) rect
{
return CGRectMake(position.x - contentSize.width*anchorPoint.x,
position.y - contentSize.height*anchorPoint.y,
contentSize.width, contentSize.height);
}
确保CCSprite.contentSize不为空。如何发生的示例:您使用CCSprite,但添加的实际内容显示在该CCSprite的子级中。