大家好请任何人都可以帮忙解决这个错误: “访问未知'生命'getter方法” 我正在获取代码的第二行(CCSprite行)下方。
GamePlayLayer.h是:
#import "cocos2d.h"
#import "Box2D.h"
#import "GLES-Render.h"
#import <Foundation/Foundation.h>
@class UILayer;
@class Insect;
@interface GamePlayLayer : CCLayer {
b2World * world;
GLESDebugDraw * debugDraw;
CCSpriteBatchNode * sceneSpriteBatchNode;
Insect * insect;
b2Body *body;
SceneUILayer * uiLayer;
double startTime;
bool gameOver;
bool gameWon;
NSMutableArray *lives;
}
- (id)initWithUILayer:(UILayer *)sceneUILayer;
@end
GamePlayLayer.m
UILayer * sr = (UILayer *)[self.parent getChildByTag:10];
CCSprite * live = [sr.lives objectAtIndex:self.lives];
[live setVisible:NO];
好吧,我必须添加以下信息:
UILayer.h(UILayer是HUD层)文件是:
@interface UILayer : CCLayer {
NSMutableArray *lives;
}
@property (nonatomic,retain) NSMutableArray *lives;
UILayer.m是:
#import "UILayer.h"
#import "GameManager.h"
@implementation UILayer
@synthesize lives;
- (id)init {
if ((self = [super init])) {
lives = [[NSMutableArray arrayWithCapacity:3]retain];
for(int i=0;i<3;i++)
{
CCSprite * life = [CCSprite spriteWithFile:@"life_Label.png"];
[life setPosition:ccp(winSize.width/18+ 32*i,290)];
[self addChild:life];
[lives addObject:life];
}
}
答案 0 :(得分:0)
编译器查看方法的方式-setVisible是可见属性的setter方法。我猜这不是你想要的。尝试将您的方法重命名为[live visible:NO];或者除了-set之外的任何东西。
答案 1 :(得分:0)
e.g。在你的.h:
@interface blah
// ...
@property (assign) NSInteger lives;
@end
然后在你的.m:
@implementation blah
@synthesize lives = _lives;
//your code
@end
答案 2 :(得分:0)
你可以:
@property int lives;
@synthesize lives;
。lives
不是int
(或可转换为int
)。但这只是对您提供的片段的猜测不足。