Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用onEnter方法cocos2d_Objective C_Cocos2d Iphone_Ios6 - Fatal编程技术网

Objective c 使用onEnter方法cocos2d

Objective c 使用onEnter方法cocos2d,objective-c,cocos2d-iphone,ios6,Objective C,Cocos2d Iphone,Ios6,我正在开发一个游戏。在我的游戏中使用音频。 对于音频,我导入SimpleAudioEngine框架。我在onEnter方法中设置音频,其他声明和编码在init方法中。在OneNet方法中添加音频后,我的屏幕的菜单按钮不起作用。在加入这个之前,一切都很好。我不明白我的代码有什么问题 这是我在onEnter方法中的代码 - (void)onEnter{ backgroundMusic=[SimpleAudioEngine sharedEngine]; [backgroundMusic

我正在开发一个游戏。在我的游戏中使用音频。 对于音频,我导入SimpleAudioEngine框架。我在onEnter方法中设置音频,其他声明和编码在init方法中。在OneNet方法中添加音频后,我的屏幕的菜单按钮不起作用。在加入这个之前,一切都很好。我不明白我的代码有什么问题

这是我在onEnter方法中的代码

- (void)onEnter{
    backgroundMusic=[SimpleAudioEngine sharedEngine];
    [backgroundMusic playBackgroundMusic:@"sonic_title_music.mp3" loop:YES];
    }
- (void)onExit{
[backgroundMusic stopBackgroundMusic];}
这是我的init方法:

- (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;

}您必须呼叫[超级用户]:

-(void) onEnter
{
    [super onEnter];

    backgroundMusic=[SimpleAudioEngine sharedEngine];
    [backgroundMusic playBackgroundMusic:@"sonic_title_music.mp3" loop:YES];
}
重写任何on*CCNode方法时都需要调用超级实现