Reputation: 121
@interface characterclass : CCSprite
{
bool alive;
int speed;
int jumpamount = 10; <--- error
}
@property bool alive;
@property int speed;
@property int jumpamount;
@end
how do i do this like in my code, I want to have a variable in my class that equals 10.
Upvotes: 0
Views: 71
Reputation: 4452
You need to assign these values in the initializer of your class's instances. Create an instance method called - (id)init
:
- (id)init{
self=[super init];
if (self) {
jumpamount=10;
}
return self;
}
Note that you no longer need to declare your ivars like that. @property
will create an ivar for you.
Upvotes: 4