2013-05-13 55 views
2

我想補充awesomeMenu在我的項目,但存在awesomemenu的文件的appdelegate中的問題 添加AwesomeMenu Appdelegate.h中的appdelegate

@interface AppDelegate : UIResponder <UIApplicationDelegate,AwesomeMenuDelegate> 
@property (strong, nonatomic) UIWindow *window; 
@end 

,並在我們的正常appdelegate.h文件有

@interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate> 
{ 
UIWindow *window_; 
UINavigationController *navController_; 
CCDirectorIOS *director_;       // weak ref 
} 

@property (nonatomic, retain) UIWindow *window; 
@property (readonly) UINavigationController *navController; 
@property (readonly) CCDirectorIOS *director; 

@end 

現在如果我改變CCdirectordelegate到AwesomeMenudelegate會有錯誤 如何實現它? 是否有可能在helloworld圖層中使用它 或者我們必須從appdelegate運行awesomemenu?

還是有可能實現兩個接口?

回答

1

如果您想要使用Cocos2d項目來編譯AwesomeMenu,您不必從AppDelegate.h中刪除CCDirectorDelegate。這是我做了什麼和工作原理:

  1. 創建一個新的項目基於默認的cocos2d模板 (如果你想成爲最新的,創造AwesomeMenu的github上項目的本地副本)
  2. 添加到AwesomeMenu的項目2子目錄:AwesomeMenu/AwesomeMenu(4個文件內)和圖像
  3. 僅修改2個文件:HelloWorldLayer.h和HelloWorldLayer.m

HelloWorldLayer.h(添加了一個進口真棒Menu.h和AwesomeMenuDelegate)

#import <GameKit/GameKit.h> 
#import "AwesomeMenu.h" 

// When you import this file, you import all the cocos2d classes 
#import "cocos2d.h" 

// HelloWorldLayer 
@interface HelloWorldLayer : CCLayer <GKAchievementViewControllerDelegate, 
             GKLeaderboardViewControllerDelegate, 
             AwesomeMenuDelegate> 
{ 
} 

HelloWorldLayer.m(刪去GameCenter的代碼修改僅init方法和添加例如AwesomeMenu菜單的方法稍加修改):

-(id) init 
{ 
    // always call "super" init 
    // Apple recommends to re-assign "self" with the "super's" return value 
    if((self=[super init])) { 
    // ask director for the window size 
    CGSize size = [[CCDirector sharedDirector] winSize]; 




    UIImage *storyMenuItemImage = [UIImage imageNamed:@"bg-menuitem.png"]; 
    UIImage *storyMenuItemImagePressed = [UIImage imageNamed:@"bg-menuitem-highlighted.png"]; 

    UIImage *starImage = [UIImage imageNamed:@"icon-star.png"]; 

    AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem2 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem3 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem4 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem5 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem6 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem7 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem8 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 
    AwesomeMenuItem *starMenuItem9 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage 
                  highlightedImage:storyMenuItemImagePressed 
                   ContentImage:starImage 
                highlightedContentImage:nil]; 

    NSArray *menus = [NSArray arrayWithObjects:starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4, starMenuItem5, starMenuItem6, starMenuItem7,starMenuItem8,starMenuItem9, nil]; 

    AwesomeMenu *menu = [[AwesomeMenu alloc] initWithFrame:[[[CCDirector sharedDirector] view] window].bounds menus:menus]; // PLS NOTE: referencing window 

    // customize menu 
    /* 
    menu.rotateAngle = M_PI/3; 
    menu.menuWholeAngle = M_PI; 
    menu.timeOffset = 0.2f; 
    menu.farRadius = 180.0f; 
    menu.endRadius = 100.0f; 
    menu.nearRadius = 50.0f; 
    */ 

    //menu.startPoint = CGPointMake(120.0, 240.0); 

    menu.delegate = self; 

    [[[CCDirector sharedDirector] view] addSubview:menu]; // PLS NOTE: referencing view 

} 
return self; 

}

希望你可以在自己的應用程序管理!