在appdelegate中添加AwesomeMenu

时间:2013-05-13 13:29:07

标签: cocos2d-iphone

我想在我的项目中添加awesomeMenu但是在awesomemenu的appdelegate文件中存在问题 Appdelegate.h

@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 个答案:

答案 0 :(得分:1)

如果您想使用Cocos2d项目编辑AwesomeMenu,则无需从AppDelegate.h中删除CCDirectorDelegate。这就是我所做的和工作:

  1. 基于默认的cocos2d模板创建一个新项目 (如果你想要更新,请创建AwesomeMenu的github项目的本地副本)
  2. 添加到AwesomeMenu的项目2子目录:AwesomeMenu / AwesomeMenu(里面有4个文件)和图像
  3. 仅修改2个文件:HelloWorldLayer.h和HelloWorldLayer.m
  4. HelloWorldLayer.h (添加了一个导入AwesomeMenu.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;
    

    }

    希望你能在自己的应用程序中管理!