我运行这段代码:
- (void)unitButtonButtonTapped:(id)sender {
[_label setString:@"Last button: Unembossed square"];
MilitaryUnits *target = nil;
target = [Peasants militaryUnits];
target.position = ccp(100, 450);
[self addChild:target];
}
我收到此错误: *由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“参数必须为非零”
这些是我的 .h 和 .m 类文件
#import "cocos2d.h"
@interface MilitaryUnits : CCSprite {
int _experience;
int _number_of_units;
int _stamina;
int _armor_level;
int _weapon_levell;
}
@property (nonatomic, assign) int experience;
@property (nonatomic, assign) int number_of_units;
@property (nonatomic, assign) int stamina;
@property (nonatomic, assign) int armor_level;
@property (nonatomic, assign) int weapon_levell;
@end
@interface Peasants : MilitaryUnits{
}
+(id)militaryUnits;
@end
#import "MilitaryUnits.h"
@implementation MilitaryUnits
@synthesize number_of_units = _number_of_units;
@synthesize stamina = _stamina;
@synthesize experience = _experience;
@synthesize armor_level = _armor_level;
@synthesize weapon_levell = _weapon_levell;
@end
@implementation Peasants
+ (id)militaryUnits {
Peasants *militaryUnits = nil;
if ((militaryUnits = [[[super alloc] initWithFile:@"Target.png"] autorelease])) {
}
return militaryUnits;
}
@end
注意,我使用的是 cocos 2d