CCMenuItem问题

时间:2011-02-07 10:46:46

标签: iphone cocos2d-iphone

我试图根据CCMenuItem这本书创建简单的菜单。这是我的MenuView.m代码 机器人什么都没有发生只是出现黑屏!没有任何菜单!

我正在使用COCOS2D 0.99.5

//
//  MenuView.m
//  Sence


#import "MenuView.h"
#import "HelloWorldScene.h"

@implementation MenuView

// in dastor hatman bayad dar menu badi neveshte shavad ke be onvane ye view shenasande shavad
+(id) scene
{
        CCScene* scene = [CCScene node];
        CCLayer* layer = [MenuView node];
        [scene addChild:layer];
        return scene;
}




-(id) init
{
        if ((self = [super init]))
        {
                CCLOG(@"init %@", self);

                // wait a short moment before creating the menu so we can see it scroll in
                [self schedule:@selector(createMenu:) interval:2];
        }
        return self;
}





- (void) menuItem1Touched {

        NSLog(@"test");
}


- (void) createMenu:(ccTime) delta {

 [self unschedule:_cmd];


        CGSize size = [[CCDirector sharedDirector] winSize];

        // set CCMenuItemFont default properties
        [CCMenuItemFont setFontName:@"Helvetica-BoldOblique"];
        [CCMenuItemFont setFontSize:40];

        // create a few labels with text and selector
        CCMenuItemFont* item1 = [CCMenuItemFont itemFromString:@"Go Back!" target:self selector:@selector(menuItem1Touched:)];


        // create the menu using the items
        CCMenu* menu = [CCMenu menuWithItems:item1, nil];
        menu.position = CGPointMake(-(size.width / 2), size.height / 2);
        menu.tag = 100;
        [self addChild:menu];

        // calling one of the align methods is important, otherwise all labels will occupy the same location
        [menu alignItemsVerticallyWithPadding:40];

}

@end

1 个答案:

答案 0 :(得分:2)

你的这一行:

CCMenuItemFont* item1 = [CCMenuItemFont itemFromString:@"Go Back!" target:self selector:@selector(menuItem1Touched:)];

应该是

CCMenuItemFont* item1 = [CCMenuItemFont itemFromString:@"Go Back!" target:self selector:@selector(menuItem1Touched)];

从menuItem1Touched更改为:menuItem1Touched ..删除:

经过测试和工作..