私はドロップダウンメニューの錯覚を作成しようとしていますが、私はサブメニュー項目を移動した後でもう何も選択しませんか?ここCocos2d Cantを移動した後にメニュー項目を選択する
私の全体のコード:
#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
ill投稿全体私のコード – mattblessed
私は自己が 'self'が入っているクラスを指していると思う – mattblessed