2011-08-24 1 views
0

내 장면 위에 몇 가지 스프라이트를 표시하고 menuitemsprite를 계속 버튼으로 표시하여 cocos2d의 모달보기를 시뮬레이션하려고합니다. 아래 코드에서는 모달을 통한 게임을 보여주고 CCMenuItemSprite를 사용하여 메뉴를 설정합니다. 접촉에 반응하지 않는 CCMenuItemImage; 그것은 효과가있다.누적 메뉴의 Cocos2d CCMenuItemSprite가 작동하지 않습니다.

-(void) gameOver { 

    CGSize size = [[CCDirector sharedDirector] winSize]; 
    self.menu.isTouchEnabled = NO; 
    CCLayer *modalLayer = [[CCLayer alloc] init]; 
    [self addChild:modalLayer z:20]; 

    CCSprite *spriteGameOver = [CCSprite spriteWithFile:@"game_over.png"]; 
    spriteGameOver.position = ccp(size.width/2,size.height/2); 

    CCLabelTTF *lblGameOver = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Game Over!\nScore %d/%d",numCorrect,questionIdx] dimensions:CGSizeMake(380, 300) alignment:CCTextAlignmentCenter fontName:@"Trebuchet MS" fontSize:50.0f]; 
    // position the label on the center of the screen 

    lblGameOver.position = ccp(size.width/2-200, size.height/2-100); 
    lblGameOver.color = ccc3(20, 20, 20); 
    lblGameOver.opacity = 0; 
    // add the label as a child to this Layer 
    [spriteGameOver addChild: lblGameOver]; 
    spriteGameOver.opacity = 0; 
    [modalLayer addChild:spriteGameOver]; 

    CCSprite *spriteGameOverBtn = [CCSprite spriteWithFile:@"mainButton.png" rect:CGRectMake(0,0,300,60)]; 
    spriteGameOverBtn.position = ccp(size.width/2,size.height/2-100); 
    CCLabelTTF *lblGameOverBtn = [CCLabelTTF labelWithString:@"Continue" dimensions:CGSizeMake(300, 60) alignment:CCTextAlignmentCenter fontName:@"Trebuchet MS" fontSize:40.0f]; 
    //lblGameOverBtn.position = ccp(size.width/2-200, size.height/2-300); 
    [lblGameOverBtn setAnchorPoint:ccp(0.0f,0.1f)]; 
    lblGameOverBtn.color = ccc3(20, 20, 20); 
    lblGameOverBtn.opacity = 0; 
    // add the label as a child to this Layer 
    [spriteGameOverBtn addChild: lblGameOverBtn]; 
    spriteGameOverBtn.opacity = 0; 

    CCMenuItemImage *itemH = [CCMenuItemImage itemFromNormalImage:@"backArrow.png" selectedImage:@"backArrowS.png" target:self selector:@selector(goToMain:)]; 
    itemH.position = ccp(size.width/2,size.height/2-100); 

    CCMenuItemSprite *mGameOverBtn = [CCMenuItemSprite itemFromNormalSprite:spriteGameOverBtn selectedSprite:nil disabledSprite:nil target:self selector:@selector(goToMain:)]; 

    CCMenu *menuGO = [CCMenu menuWithItems: itemH,mGameOverBtn, nil]; 
    menuGO.position = ccp(0, 0); 

    [modalLayer addChild:menuGO z:21]; 




    [lblGameOverBtn runAction:[CCSequence actions:[CCDelayTime actionWithDuration: 1.75f],[CCFadeIn actionWithDuration: 1.75f],nil]]; 

    [spriteGameOverBtn runAction:[CCSequence actions:[CCDelayTime actionWithDuration: 1.75f],[CCFadeIn actionWithDuration: 1.75f],[CCDelayTime actionWithDuration: 3.75f],nil]]; 


    [lblGameOver runAction:[CCSequence actions:[CCDelayTime actionWithDuration: 1.75f],[CCFadeIn actionWithDuration: 1.75f],[CCDelayTime actionWithDuration: 3.75f],nil]]; 

    [spriteGameOver runAction:[CCSequence actions:[CCDelayTime actionWithDuration: 1.75f],[CCFadeIn actionWithDuration: 1.75f],[CCDelayTime actionWithDuration: 3.75f],nil]]; 

    //[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration: 2.75f],[CCCallFunc actionWithTarget:self selector:@selector(goToMain:)], nil]]; 

} 

답변

0

터치 디스패처로 장면을 등록했는데 선택자가 실제로 작업을 수행 했습니까?

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO] 
+0

씬은 터치에 반응하여 게임 오버 포인트에 도달하는 데 사용됩니다. 사실, 메뉴 상단에 Game over sprite를 표시하면 메뉴가 계속 응답합니다. 그래서 그것을 치료하기 위해 기본 메뉴가 비활성화되었습니다. 그래서 지금 내가 일하고 싶은 메뉴는 최고 Z 순서이며 활성화되어 있습니다. 내 추락은 CCMenuItemImage를 투명 이미지로 만들고 그 이미지로 끝내는 것입니다. – Nungster

1

CCMenuItemSprite에서도 동일한 문제가 발생합니다. CCMenuItemSprite 클래스가 약간 버그가있는 것처럼 보입니다. 제 경우에는 접촉에 반응하지 않습니다. 하지만 그것은 CCMenuItemSprite 내부의 다중 레이어 Sprites와 관련이 있다는 것을 알게되었습니다. 그래서 단일 레이어 Sprite를 사용하면 작동하지만 여러 스프라이트가 포함 된 Sprite를 사용할 때는 그렇지 않습니다.

지금이 초기화 된 직후 CCMenuItemSprite의 적절한 크기로 contentSize을 설정하는 것입니다 내 '준비 - 아직'솔루션 : 그것은 지금 터치 이벤트를받는 것

 CCMenuItemSprite * menuItem = [CCMenuItemSprite itemWithNormalSprite:multiLayeredSprite selectedSprite:nil target:self selector:@selector(clickHandler:)]; 
    [s setContentSize:backgroundSprite.contentSize]; 
    CCMenu * menu = [CCMenu menuWithItems: 
      menuItem, 
      nil]; 

. 내가 가진 유일한 문제는 Rectangle의 위치입니다. 여전히 오른쪽 상단에 있습니다. 이 문제를 해결하는 방법을 알아 내려고 노력할 것입니다. 이 부분이 약간의 문제를 명확히 밝히기를 바랍니다.

관련 문제