0

it is my first cocos2d app I try, and I am following example from book Learning Cocos2d but it seems it refers to an older version of cocos.

I have created a scene, and in its init method I add 2 layers.

Now the tutorial says, that in my delegate.m I should add this line (to be precise change the previous one that strted the HelloWorldScene) :

[director_ runWithScene:[GameScene node]];

But I am getting an error.

The weird thing is that it does not use that code at all,but that one:

[director_ pushScene: [IntroLayer Scene]];

But if I use this, I also get an error:

[director_ pushScene: [GameScene node]];

My GameScene is here:

#import "GameScene.h"

@implementation GameScene
-(id) init{
    self=[super init];
    if (self!=nil){
        BackgroundLayer *backgroundLayer=[BackgroundLayer node];
        [self addChild:backgroundLayer z:0];

        GameplayLayer *gameplayLayer=[GameplayLayer node];
        [self addChild:gameplayLayer z:5];
    }
}

@end

and the errors I get:

EXC_BAD_ACCESS in both cases.

How can I start this scene from my appdelegate?

ghostrider
  • 5,131
  • 14
  • 72
  • 120
  • what version of cocos2d and xcode you are using? – MrWaqasAhmed Jan 23 '13 at 06:44
  • Add an exception breakpoint in Xcode. http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4 Then you can tell us more about the error. EXC_BAD_ACCESS is a generic error. – CodeSmile Jan 23 '13 at 12:11

2 Answers2

1

You have to send Scene in pushScene method argument of director, as

[director_ pushScene: [GameScene scene]];
MrWaqasAhmed
  • 1,479
  • 12
  • 12
0

Thanks for your help!

I did use that:

[director_ pushScene: [GameScene node]];

but the actual problem is that in my GameScene init method I have forgotten to return self.

ghostrider
  • 5,131
  • 14
  • 72
  • 120