0

我现在在我的 iPhone Coco2d 游戏中发现了一个问题,这是我的第一个 Objective-c 游戏。我的二传手似乎没有工作!如果我在将其设置为 NULL(如果为 Stringed)或我得到一个致命的错误访问异常之后尝试访问属性,那么我一定做错了,这是我的代码:

@interface Character : CCNode 
    {
        CCSprite* sprite;
        int width;
        int height;
    }
    @property (retain) CCSprite* sprite;
    @property int width;
    @property int height;
@end

和实施:

@implementation Character

@synthesize sprite;
@synthesize width;
@synthesize height;

-(id) init
{
    if((self=[super init])) {
        [self setSprite :[CCSprite spriteWithFile:@"character.png"]];
        [self setWidth:28];
        [self setHeight:28];
        NSLog(@"About to try get height...");
        NSLog([self height]); //bad access exception
    }
}
4

1 回答 1

4

这是格式不正确的日志语句

NSLog(@"Height :%d", [self height]);

NSLog查找要打印的字符串,您已经给它一个不能更改为对象的 int

于 2012-06-14T08:23:11.783 回答