2
votes

I am developing a game. and use audio in my game. for audio I import SimpleAudioEngine framework. I set audio in onEnter method and other declaration and coding are in init method. After adding audio in onEnter method, my screen's menu buttons are not working. and before adding this everything was working fine. I did not understand that whats wrong with my code.

here is my code in onEnter method.

- (void)onEnter{
    backgroundMusic=[SimpleAudioEngine sharedEngine];
    [backgroundMusic playBackgroundMusic:@"sonic_title_music.mp3" loop:YES];
    }
- (void)onExit{
[backgroundMusic stopBackgroundMusic];}

and this is my init method:

- (id)init{
self = [super init];
if (self) {
    controller = (AppController *)[[UIApplication sharedApplication] delegate];
    CGSize size=[[CCDirector sharedDirector]winSize];
    [CCMenuItemFont setFontName:@"Marion"];
    [CCMenuItemFont setFontSize:30];
    CCMenuItem *newGame=[CCMenuItemFont itemWithString:@"New Game" target:self selector:@selector(newGame)];
    CCMenuItem *modes=[CCMenuItemFont itemWithString:@"Modes" target:self selector:@selector(modes)];
    CCMenuItem *help=[CCMenuItemFont itemWithString:@"Help" target:self selector:@selector(help)];
    CCMenuItem *setting=[CCMenuItemFont itemWithString:@"Setting" target:self selector:@selector(setting)];
    menu=[CCMenu menuWithItems:newGame,modes,setting,help, nil];
    [menu alignItemsVerticallyWithPadding:10];
    CCLOG(@"width== %f",size.width);
    if(size.width==320)
        menu.position=ccp(size.width/2, size.height/2);
    else
        menu.position=ccp(size.width/2, size.height/2);
    [self addChild:menu];
}
return self;

}

1

1 Answers

5
votes

You must call [super onEnter]:

-(void) onEnter
{
    [super onEnter];

    backgroundMusic=[SimpleAudioEngine sharedEngine];
    [backgroundMusic playBackgroundMusic:@"sonic_title_music.mp3" loop:YES];
}

Calling the super implementation is required when overriding any of the on* CCNode methods.