2

我想在我的项目中添加awesomeMenu,但是Appdelegate.h中awesomemenu的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 更改为 AwesomeMenudlegate 会有错误如何实现?是否有可能在 helloworld 层中使用它,或者我们必须从 appdelegate 操作 awesomemenu?

还是有可能实现两个接口?

4

1 回答 1

1

如果你想将 AwesomeMenu 与 Cocos2d 项目相结合,你不必从 AppDelegate.h 中删除 CCDirectorDelegate。这就是我所做的工作:

  1. 基于默认的cocos2d模板新建一个项目(如果你想保持最新,创建一个AwesomeMenu的github项目的本地副本)
  2. 添加到 AwesomeMenu 的项目 2 子目录:AwesomeMenu/AwesomeMenu(里面有 4 个文件)和 Images
  3. 只修改 2 个文件:HelloWorldLayer.h 和 HelloWorldLayer.m

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(仅修改init方法,删除GameCenter代码并添加示例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;

}

希望您可以在自己的应用程序中进行管理!

于 2013-05-13T14:56:20.313 回答