0
我試圖創建一個下拉菜單的錯覺,但是在移動子菜單項之後,我不能再選擇它們了嗎?Cocos2d在移動它們後不能選擇菜單項
我在這裏的全部代碼:
#import "HelloWorldLayer.h"
CCMenuItem *playDown;
CCMenuItem *playUp;
CCMenuItemToggle *play;
CCMenuItem *help;
CCMenuItem *options;
int down;
// HelloWorld implementation
@implementation HelloWorldLayer
+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init {
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if((self=[super init]))
{
self.isTouchEnabled = TRUE;
[CCMenuItemFont setFontSize:70];
playDown = [CCMenuItemFont itemFromString:@"Play" target:self selector:@selector(playDown:)];
playUp = [CCMenuItemFont itemFromString:@"Play" target:self selector:@selector(playUp:)];
play = [CCMenuItemToggle itemWithTarget:self selector:@selector(playDown:) items:playDown,playUp, nil];
help = [[CCMenuItemFont itemFromString:@"Help" target:self selector:@selector(help:)] retain];
help.position = ccp(512,350);
CCMenu *menu = [CCMenu menuWithItems:play,help, nil];
[self addChild:menu];
play.position = ccp(0,300);
down = 0;
[self schedule:@selector(itemSelected) interval:0.01];
}
return self;
}
-(void) playDown: (id) sender {
if (down == 0) {
if ([help parent] != self) {
help = [[CCMenuItemFont itemFromString:@"Help" target:self selector:@selector(help:)] retain];
[self addChild:help];
help.position = ccp(512,350);
[help runAction:[CCMoveTo actionWithDuration:1 position:ccp(512,500)]];
NSLog(@"Added Help");
}
if ([options parent] != self) {
options = [[CCMenuItemFont itemFromString:@"Options" target:self selector:@selector(options:)] retain];
[self addChild:options];
options.position = ccp(512,650);
[options runAction:[CCMoveTo actionWithDuration:1 position:ccp(512,600)]];
NSLog(@"Added Options");
down = 1;
}
return;
}
if (down == 1) {
if ([options parent] == self) {
[self removeChild:options cleanup:YES];
}
if ([help parent] == self) {
[self removeChild:help cleanup:YES];
down = 0;
}
return;
}
}
-(void) playUp: (id) sender {
}
-(void) help: (id) sender {
NSLog(@"Help Selected");
}
-(void) options: (id) sender {
NSLog(@"Options Seleted");
}
-(void) itemSelected {
if (help.isSelected) {
[self runAction:[CCCallFunc actionWithTarget:self selector:@selector(help:)]];
}
if (options.isSelected) {
[self runAction:[CCCallFunc actionWithTarget:self selector:@selector(options:)]];
}
}
- (void) dealloc
{
[super dealloc];
}
@end
一切似乎是工作像加了精靈和移動菜單項,我用一個切換信號天氣派下拉菜單菜單顯示不以顯示
在上面的代碼中,什麼類是「自我」? – YvesLeBorg 2012-02-12 18:26:11
虐待我的整個代碼 – mattblessed 2012-02-12 21:59:49
我認爲self是指'self'所在的類 – mattblessed 2012-02-12 22:02:37