//1.点击后直接在@R_404_6137@添加Layer
auto layer = SetLayer::create();this->addChild(layer);
2.设置d窗界面SetLayer.h
#ifndef __SET_LAYER_H__#define __SET_LAYER_H__#include "cocos2d.h"#include "cocostudio/CocoStudio.h"#include "ui/CocosGUI.h"using namespace cocos2d::ui;class SetLayer : public cocos2d::Layer{public: virtual bool init(); CREATE_FUNC(SetLayer);private: ImageVIEw* Image_back; Layout* Panel_1; voID closeLayertouch(cocos2d::Ref *pSender,Widget::touchEventType type); voID close(Node* pSender);};#endif // __SET_LAYER_H__
设置d窗界面SetLayer.cpp
#include "cocostudio/CocoStudio.h"#include "ui/CocosGUI.h"#include "SetLayer.h"USING_NS_CC;using namespace cocostudio::timeline;using namespace cocos2d::ui;bool SetLayer::init(){ ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } auto rootNode = csloader::createNode("SetLayer.csb"); Panel_1 = (cocos2d::ui::Layout*)rootNode->getChildByname("Panel_1"); auto director = Director::getInstance(); //1.真机可视区域 Rect vIDiableRect = director->getopenGLVIEw()->getVisibleRect(); Panel_1->setAnchorPoint(Vec2(0.5,0.5)); //居中 Panel_1->setposition(Vec2(vIDiableRect.origin.x+ vIDiableRect.size.wIDth/2,vIDiableRect.origin.y+ vIDiableRect.size.height/2)); //2.关闭按钮 Image_back = (ImageVIEw*)Helper::seekWidgetByname(Panel_1,"Image_back"); Image_back->settouchEnabled(true); Image_back->addtouchEventListener(CC_CALLBACK_2(SetLayer::closeLayertouch,this)); Image_back->setTag(1); addChild(rootNode); //缩放至可见 Panel_1->setScale(0); Panel_1->runAction(Scaleto::create(0.2,1.0)); return true;}voID SetLayer::closeLayertouch(cocos2d::Ref * pSender,Widget::touchEventType type){ switch (type) { case cocos2d::ui::Widget::touchEventType::ENDED: //手指点中按钮,松开。 cclOG("ENDED"); if (((ImageVIEw*)pSender)->getTag() == 1) { //关闭当前层(先缩放至不可见,再执行函数移除当前layer) auto seq = Sequence::create(Scaleto::create(0.2,0),CallFuncN::create(CC_CALLBACK_1(SetLayer::close,this)),NulL); Panel_1->runAction(seq); } break; }}voID SetLayer::close(Node * pSender){ this->removeFromParentAndCleanup(true);}总结
以上是内存溢出为你收集整理的cocos2d-x制作d出层(Layer)全部内容,希望文章能够帮你解决cocos2d-x制作d出层(Layer)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)