tags:

views:

208

answers:

2

i'm using v99.0

onEnter is not being called when my sprite is added to the layer and the layer's scenee is displayed. the sprite appears correctly but onenter is not being called.

the funny thing is that i'm doing exactly the same with other sprites and their onenter methods are being called fine.

Is this a bug?

In app delegate:

[[CCDirector sharedDirector] runWithScene: [TilesView scene]];

In init method of TilesView (which is a subclass of CClayer):

CCSpriteTouch *backArrow = [CCSprite spriteWithFile:@"back arrow.png"]; [self addChild:backArrow];

Note: In the same init method i create other sprites which does result in their onEnter methods being called:

TileSprite *tile = [TileSprite spriteWithFile:@"singleTile.png"];
[self addChild:tile];

the code for both sprite classes is identical.

A: 

In your TilesView class do you have a call to the super class onEnter? i.e....

-(void)onEnter
{
   ... your custom code ...

    [super onEnter];
}

I had forgotten to do this with some work recently and it wreaked havok with Cocos. Did you try tracing through some of the Cocos code to see where the logic is failing to reach the point where your TilesView::onEnter call should be made?

If you paste in your declaration of the TilesView class that could help clarify things as well.

Rob Segal
A: 

I spotted it... sorry, it was a silly mistake. I had subclassed CCSprite for use with touches but when I created an instance of the class i did so with CCSprite not my custom class:

CCSpriteTouch *backArrow = [CCSprite spriteWithFile:@"back arrow.png"];

so CCSprite's onenter method was being called, not CCSpriteTouch's.

Remover