2013-11-25 4 views
0

아래 코드에서 선택기를 만드는 데 문제가 있습니다. 로그조차도 아무 것도 표시하지 않습니다. 이 문제를 어떻게 해결할 수 있습니까?CCMenuItemSprite CCLabelBMFont 선택기가 작동하지 않습니다.

-(void)displaySettingsMenuItems { 

CCSprite *buttonHolder = [CCSprite spriteWithFile:@"buttonHolder.png"]; 
buttonHolder1.position = ccp(screenSize.width/2, screenSize.height/2); 
[self addChild:buttonHolder z:ZPos]; 
CCMenuItemSprite *instructionsItemSprite = [CCMenuItemSprite itemWithTarget:self selector:nil]; 

CCLabelBMFont *instructionsLabelFont = [CCLabelBMFont labelWithString:@"instructions" fntFile:@"TestingFont.fnt"]; 
CCMenuItemLabel *instructionsItemLabel = [CCMenuItemLabel itemWithLabel:instructionsLabelFont target:self selector:@selector(instructionsLayer)]; 

instructionsLabelFont.position =ccp(screenSize.width/2, 0.99*screenSize.height/2); 
[instructionsItemSprite addChild: instructionsItemLabel z:ZPos]; 
[self addChild:instructionsItemSprite z:ZPos]; 
} 

선택기 방법 :

-(void)instructionsLayer { 
CCLOG(@"code is okay"); 
[[MenuManager sharedMenuManager] runWithPrePlayMenu:kInstructions]; 
} 

답변

0

당신이 CCMenu (안 CCMenuItem)로 instructionsItemLabel 메뉴 항목을 추가해야 다음 장면에 메뉴를 추가 할 수 있습니다. CCMenu는 메뉴 항목 (하나 또는 여러 항목)의 자리 표시 자이며 CCLayer 클래스를 확장합니다. 내장 된 메뉴 항목에 대한 터치 처리와 특정 메뉴 항목과 관련된 터치 이벤트가있을 때 해당 메뉴 항목을 호출하는 논리를 제공합니다.

-(void)displaySettingsMenuItems { 

    CCSprite *buttonHolder = [CCSprite spriteWithFile:@"buttonHolder.png"]; 
    buttonHolder.position = ccp(screenSize.width/2, screenSize.height/2); // <- you had buttonHolder1 ivar 
    [self addChild:buttonHolder z:zPos]; 

    CCLabelBMFont *instructionsLabelFont = 
     [CCLabelBMFont labelWithString:@"instructions" fntFile:@"TestingFont.fnt"]; 
    CCMenuItemLabel *instructionsItemLabel = 
     [CCMenuItemLabel itemWithLabel:instructionsLabelFont 
           target:self 
           selector:@selector(instructionsLayer)]; 

    CCMenu *menu = [CCMenu menuWithTtems:instructionsItemLabel,nil]; 
    menu.position = buttonHolder.position; 
    [self addChild:menu]; 
} 
+0

어떻게 여러 CCMenuItemLabel의 레이블에 대한 올바른 위치를 얻을 수 있습니까? – errorallergic

관련 문제