【发布时间】:2018-03-05 16:40:27
【问题描述】:
刚开始希望这不是一个太菜鸟的问题
对于我正在开发的游戏,我希望有不同的选项卡,其效果类似于 iOS 底部选项卡控制器,如图所示:
我不知道如何创建这个?这一切都应该在一个场景中打开和关闭不同的图层吗?我应该使用多个场景吗?
似乎将其保留在一个场景中并不能真正扩展。这个一般是怎么做的,cocos2d-x有什么容器的概念吗?
【问题讨论】:
标签: cocos2d-x
刚开始希望这不是一个太菜鸟的问题
对于我正在开发的游戏,我希望有不同的选项卡,其效果类似于 iOS 底部选项卡控制器,如图所示:
我不知道如何创建这个?这一切都应该在一个场景中打开和关闭不同的图层吗?我应该使用多个场景吗?
似乎将其保留在一个场景中并不能真正扩展。这个一般是怎么做的,cocos2d-x有什么容器的概念吗?
【问题讨论】:
标签: cocos2d-x
我建议你有 2 层:
第一层将处理图像。我想你可以使用 图像视图。并以您想要的尺寸放置它们。
第二部分是一个标签菜单,可以用第二个实现 您将在其中添加按钮和背景的图层。为了 按钮使用 Button 类。
希望对你有帮助。
【讨论】:
bool ScreenController::init(){
if(Layer::init())
{
footer = Footer::create();
footer->setDelegate(this);
this->addChild(footer,3);
auto homeLayer= HomeView::create(psize,this);
homeLayer->setPosition(Point(0,footer->getBoundingBox().getMaxY()));
// homeLayer->setAllApiFireTo(this);
auto rakeLayer = RakeView::create(psize);
rakeLayer->setPosition(Point(0,footer->getBoundingBox().getMaxY()));
rakeLayer->setDelegate(this);
Tablayers = LayerMultiplex::create();
Tablayers->addLayer(homeLayer);
Tablayers->addLayer(rakeLayer);
this->addChild(Tablayers);
}
}
void ScreenController::TabControllerAction(ViewDisplayType type) {
Tablayers -> switchTo(index);
}
bool Footer::init(){
if(Layer::init())
{
this->setContentSize(Size(constantDeviceSize.width,108*gamescaleY));
// auto btlayer = LayerColor::create(Color4B::RED,this->getContentSize().width,this->getContentSize().height);
//
// this->addChild(btlayer);
SubButton*sb1 = SubButton::create(Size(this->getContentSize().width/5,this->getContentSize().height),"Home.png","Home.png",CC_CALLBACK_2(Footer::callMenuItem, this) );
sb1->setAnchorPoint(Point(0,0));
sb1->setPosition(Point(0,0));
sb1->addTitleText("Home", SFUI_Regular.c_str());
sb1->colorEfact(true);
sb1->setColorbtn(Color3B::WHITE,colorSkyBlue3B);
this->addChild(sb1);
SubButton*sb2 = SubButton::create(Size(this->getContentSize().width/5,this->getContentSize().height),"Balance.png","Balance.png",CC_CALLBACK_2(Footer::callMenuItem, this));
sb2->setAnchorPoint(Point(0,0));
sb2->setPosition(Point(sb2->getBoundingBox().size.width,0));
sb2->addTitleText("Rake", "arial.ttf");
sb2->colorEfact(true);
sb2->setColorbtn(Color3B::WHITE,colorSkyBlue3B);
this->addChild(sb2);
sb1->setDisplayType(myHomeView);
sb2->setDisplayType(myRakeView);
}
void Footer::selectionByController(int tab)
{
auto tmpbar = dynamic_cast<SubButton *>(this -> getChildren().at(tab-1));
callMenuItem(tmpbar, TouchBegan);
}
void Footer::callMenuItem(Ref *sender, TouchEvent event)
{
if(event==TouchBegan)
{
auto sbitem = (SubButton*)sender;
if(event==TouchBegan)
{
sbitem->selected();
if(this->getDelegate())
{
this->getDelegate()->TabControllerAction(sbitem->getDisplayType());/*call to parant*/
}
CCLOG("CLICKED!->%d",sbitem->getTag());
}
for (int i = 0; i < this->getChildren().size(); i++)
{
auto tmpbar = dynamic_cast<SubButton *>(this -> getChildren().at(i));
if (tmpbar != NULL && tmpbar -> getTag() != sbitem -> getTag())
{
tmpbar ->unSelected();
}
}
}
}
【讨论】: