gpt4 book ai didi

iphone - Cocos2d CCMenuItemSprite 在堆叠菜单中不起作用

转载 作者:行者123 更新时间:2023-11-29 05:00:07 24 4
gpt4 key购买 nike

我试图通过在场景上显示一些 Sprite 并显示 menuitemsprite 作为继续按钮来模拟 cocos2d 中的模态视图。在下面的代码中,我通过模态显示我的游戏,并使用 CCMenuItemSprite 设置菜单;它不响应触摸,以及 CCMenuItemImage;这确实有效。

    -(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]];

}

最佳答案

我对 CCMenuItemSprite 也有同样的问题。看起来 CCMenuItemSprite 类有点错误。就我而言,它对触摸没有反应。但我发现它与 CCMenuItemSprite 内的多层 Sprites 有关。因此,当我使用单层 Sprite 时,它​​可以工作,但当我使用包含多个嵌入 Sprite 的 Sprite 时,它​​就不起作用。

我现在的“尚未准备好”解决方案是在初始化后立即将 contentSize 设置为 CCMenuItemSprite 的适当大小:

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

它现在正在接收触摸事件。我现在遇到的唯一问题是矩形的位置......它仍然在右上角。我现在会尝试找出如何解决这个问题。希望这能澄清一些问题。

关于iphone - Cocos2d CCMenuItemSprite 在堆叠菜单中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7175378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com