我已经尝试过这个教程(http://www.raywenderlich.com/4666/how-to-create-a-hud-layer-with-cocos2d),但你可能会说我没用与他们相同的教程,但几乎相同的设置。我相信我一步一步地跟着它。但是我得到了错误(箭头所示的位置:< ----)'未知的类型名称'settingsMenu''和'预期的类型':
mainMenu.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
mainMenu.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;
}
settingsMenu.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
settingsMenu.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;
}
感谢您的时间!我认为没有必要再发布任何代码,但如果还有其他地方可能导致此问题,请告诉我,我会发布代码。
答案 0 :(得分: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