Reputation: 552
I run this code:
- (void)unitButtonButtonTapped:(id)sender {
[_label setString:@"Last button: Unembossed square"];
MilitaryUnits *target = nil;
target = [Peasants militaryUnits];
target.position = ccp(100, 450);
[self addChild:target];
}
And I get this error: * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil'
These are my .h and .m class files
#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
Note, I'm using cocos 2d
Upvotes: 1
Views: 2944
Reputation: 9079
looks to me like your sprite is nil, ie the file "Target.png" is not found. Make certain the file name has the same case (in finder) as you spelled out in your code, and that the file is included in the target's membership in Xcode.
Also
+ (id)militaryUnits {
Peasants *militaryUnits;
if ((militaryUnits = [[[super alloc] initWithFile:@"Target.png"] autorelease])) {
return militaryUnis;
} else {
CCLOGERROR(@"your favorite whine style for errors like file not found");
return nil;
}
}
Upvotes: 2