@interface characterclass : CCSprite
{
bool alive;
int speed;
int jumpamount = 10; <--- error
}
@property bool alive;
@property int speed;
@property int jumpamount;
@end
在我的代码中应该怎么实现这,我想要在类中有一变量等于10
@interface characterclass : CCSprite
{
bool alive;
int speed;
int jumpamount = 10; <--- error
}
@property bool alive;
@property int speed;
@property int jumpamount;
@end
在我的代码中应该怎么实现这,我想要在类中有一变量等于10
你需要在初始化类实例的时候,指定这些值。创建一个实例方法命名为- (id)init
- (id)init{
self=[super init];
if (self) {
jumpamount=10;
}
return self;
}
不需再声明ivar了,@property会帮你创建的。