Problem With CCMenuItem
Iam trying to create simple menu according to the book CCMenuItem . here is my MenuView.m code bot nothing happens just a black screen appears ! without any menu !
iam working with 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
Your this line:
CCMenuItemFont* item1 = [CCMenuItemFont itemFromString:@"Go Back!" target:self selector:@selector(menuItem1Touched:)];
should be
CCMenuItemFont* item1 = [CCMenuItemFont itemFromString:@"Go Back!" target:self selector:@selector(menuItem1Touched)];
Change from menuItem1Touched: to menuItem1Touched.. Remove the :
Tested and works..
精彩评论