0

我希望弹出一个新层,使该层下的所有层都变暗。

比如记分板、对话面板,希望能更清楚些。

可能吗?

欢迎您的评论

4

2 回答 2

1

在我的项目中,我为暂停层执行了此操作:

CCLayerColor *bgLayer = CCLayerColor::create(ccc4(0,0,0,170));
this->addChild(bgLayer);

//Add other pause menu elements (Title, Resume button, quit button, etc.)

我在按钮点击事件中添加了这个,整个屏幕变得昏暗。只要确保这一层在你的其他层之上。

于 2013-09-26T19:57:41.613 回答
0

我最近为一个游戏做了这个,我使用了一个 Scale9Sprite 作为一个对话框,并使用了一个 LayerColor 来使其他所有东西变暗。

您需要将最低 z 索引处的 LayerColor 作为孩子添加到 YourDialogBoxClassName (本身需要从 Layer 继承),我将 LayerColor 实例添加到 z 索引 0 为我。

此外,如果要添加动作(例如 ScaleTo)以提供弹出效果,请确保覆盖 setScaleX 和 setScaleY 以使背景 LayerColor 具有 1.0f 的恒定比例。如果您向对话框添加轻微旋转,您可能还希望对 setRotationX 和 setRotationY 方法执行此操作。

您可能还希望禁用对背景层的所有触摸,我通过覆盖方法 onEnter 和 onExit 做到了这一点:

void YourDialogBoxClassName::onEnter() {
    Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, Menu::HANDLER_PRIORITY, true);
    Layer::onEnter();
}

void YourDialogBoxClassName::onExit() {
    Director::getInstance()->getTouchDispatcher()->removeDelegate(this);
    Layer::onExit();
}

然后你需要在 YourDialogBoxClassName:

bool YourDialogBoxClassName::ccTouchBegan(Touch * touch, Event * event ) {
    //Consumes the touch
    return true; 
}

因为您将背景添加到较低的 z 索引,所以触摸仍将注册主对话框精灵(或您正在显示的任何内容)中的菜单项。

于 2013-09-25T11:04:12.183 回答