Hello, I'm new of Cocos2D. I can't find a solution for my problem in the forum and also in the sources.
Basically I want to understand how to have a main class and some actors classes (main character, monsters...)
My approach at the moment is to have a "main class" and some other classes wich inherit from NSObject (in the code at bottom i used CCLayer).
I can instance the classes but i don't know how to draw the "hero" or "monsters" sprites on the main scene!
Help :(
for example...
HERO CLASS
@interface hero: CCLayer
{
CCSprite *currentsprite;
}
@property(retain,nonatomic) CCSprite *currentsprite;
-(void)method;
@end
@implementation hero
@synthesize currentsprite;
-(id)init
{
self=[super init];
return self;
}
-(void) method
{
currentsprite=[currentsprite initWithFile:@"hero.png"];
currentsprite.position=ccp(100,100);
[self addChild:currentsprite];
}
- (void)dealloc
{
[super dealloc];
}
@end
than in mine main class I alloc a "hero" object, call "method" and add as child to the scene....crash! :(