如果你想将 AwesomeMenu 与 Cocos2d 项目相结合,你不必从 AppDelegate.h 中删除 CCDirectorDelegate。这就是我所做的工作:
- 基于默认的cocos2d模板新建一个项目(如果你想保持最新,创建一个AwesomeMenu的github项目的本地副本)
- 添加到 AwesomeMenu 的项目 2 子目录:AwesomeMenu/AwesomeMenu(里面有 4 个文件)和 Images
- 只修改 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;
}
希望您可以在自己的应用程序中进行管理!