corgichu
corgichu

Reputation: 2600

CCSprite not showing up

I'm trying to learn Objective-C and how to do some simple animations for iOS with cocos2d.

I was using this tutorial and got the animating to work, but I wanted to take the code out of the main class and put it into a separate class. (http://www.raywenderlich.com/32045/how-to-use-animations-and-sprite-sheets-in-cocos2d-2-x)

So I made a new class called Pet which extends CCNode (here is the interface):

@interface Pet : CCNode {
    BOOL moving;
    int touchCount;
}

@property (nonatomic, assign) CCAction *walkAction;
@property (nonatomic, assign) CCAction *cuteAction;
@property (nonatomic, assign) CCAction *moveAction;
@property (nonatomic, assign) CCSprite *sprite;

- (id) initPetWithName:(NSString *)name xPosition:(int)x yPosition:(int)y;
- (BOOL) isTouchedByPoint:(CGPoint)point;
- (void) moveToPoint:(CGPoint)point;

@end

It has a CCSprite object, which is initialized in init with:

self.sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@_%d.png", name, 4]];

There are no errors in the initialization, but it doesn't show up in the screen.

The CCLayer class has this in its init method:

-(id) init {
    if((self = [super init])) {
        CGSize winSize = [[CCDirector sharedDirector] winSize];

        self.pet = [[Pet alloc] initPetWithName:@"Waffles"
                xPosition:winSize.width/2 yPosition:winSize.height/2];
        [self addChild:self.pet];
        self.isTouchEnabled = YES;
    }
    return self;
}

Upvotes: 0

Views: 335

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

I don't see where you're adding the sprite as child. Might that be it?

I once wrote an article that explains many potential causes for curiously absent nodes.

Upvotes: 1

Related Questions