0

我试过按照本教程(http://www.raywenderlich.com/4666/how-to-create-a-hud-layer-with-cocos2d)但是你可能会说我没有使用本教程与他们相同,但设置几乎相同。我相信我已经一步一步地遵循了它。但是我得到了错误(箭头显示的位置:<----)'未知类型名称'settingsMenu''和'预期类型'分别:

主菜单.h:

//  mainMenu.h


#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Constants.h"
#import "SceneManager.h"
#import "settingsMenu.h"



@interface mainMenu : CCLayer {  
    settingsMenu * _settings; <----
}

@property (nonatomic, assign) BOOL iPad;

+ (id)scene;
- (id)initWithsettingsMenu:(settingsMenu *)settings; <----

@end

主菜单.m:

//  mainMenu.m

#import "mainMenu.h"  
#import "gameData.h"
#import "gameDataParser.h"
#import "SimpleAudioEngine.h"
#import "settingsMenu.h"

@implementation mainMenu

@synthesize iPad;

+ (id)scene {
    CCScene *scene = [CCScene node];
    settingsMenu *settings = [settingsMenu node];
    [scene addChild:settings z:1];
     mainMenu *menuLayer = [[[mainMenu alloc] initWithsettingsMenu:settings] autorelease];
     [scene addChild:menuLayer];

    return scene;
}

设置菜单.h:

//  settingsMenu.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Constants.h"
#import "SceneManager.h"

@interface settingsMenu: CCLayer {
    CCMenuItem *_musicOn;
    CCMenuItem *_musicOff;
    CCMenuItem *_invertControlsOn;
    CCMenuItem *_invertControlsOff;
}

@property (nonatomic, assign) BOOL iPad;
@property (nonatomic, assign) BOOL settings;

@end

设置菜单.m:

//  settingsMenu.m


#import "settingsMenu.h"
#import "gameData.h"
#import "gameDataParser.h"
#import "SimpleAudioEngine.h"
#import "mainMenu.h"


@implementation settingsMenu

- (id)init{
    if( (self=[super init])) {

        // Determine Screen Size
        CGSize screenSize = [CCDirector sharedDirector].winSize;

        self.iPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;

        if (self.iPad){
            CCSprite *background = [CCSprite spriteWithFile:@"settingsiPad.png"];
            background.position = ccp(screenSize.width/2, screenSize.height/2);
            [self addChild:background];
        }

        else if (screenSize.height > 490){
            CCSprite *background = [CCSprite spriteWithFile:@"settingsiPhoneFive.png"];
            background.position = ccp(screenSize.width/2, screenSize.height/2);
            [self addChild:background];
        }

        else{
             CCSprite *background = [CCSprite spriteWithFile:@"settingsiPhone.png"];
             background.position = ccp(screenSize.width/2, screenSize.height/2);
            [self addChild:background];
        }
     [self addButtons];

    }
    return self;
}

谢谢你的时间!我认为没有必要发布更多代码,但如果还有其他可能导致此问题的地方,请告诉我,我会发布代码。

4

1 回答 1

1

gameLayer .h:(我去掉了大部分不必要的东西)

//  GameLayer.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface GameLayer : CCLayer {
    CCLayer *HudLayer;
}
@property (nonatomic, retain) CCLayer *HudLayer;

+(id)scene;
@end

然后在 .m 你

@synthesize HudLayer;

然后在init,

//HUD Layer setup

        HudLayer = [[[CCLayer alloc] init] autorelease];
        [self addChild:HudLayer];
             //add stuff in the HUD here...


        CCMenuItem *Mainmenu = [[[CCMenuItemFont itemWithString:@"Main Menu" target:self selector:@selector(MainMenu:)] retain]autorelease];

        Mainmenu.position = ccp(size.width /2-Mainmenu.rect.size.width,size.height /2-Mainmenu.rect.size.height);
        CCMenu *Hudmenu = [CCMenu menuWithItems: Mainmenu, nil];
        [HudLayer addChild:Hudmenu];
    //End HUD Layer setup
于 2012-10-07T17:28:24.063 回答