首页 > 代码库 > cocos2d-x 3.2 关闭按钮点击立马销毁自己报错
cocos2d-x 3.2 关闭按钮点击立马销毁自己报错
cocos2d-x 3.2 Button点击事件里调用移除当前层报错
http://www.th7.cn/program/ios/201408/271227.shtml
诡异的错误,点击关闭按钮,居然进入
void Widget::onTouchEnded(Touch *touch, Event *unusedEvent)
两次,第二次报错。
修改下这个函数:调换一下位置就行了
void Widget::releaseUpEvent(){ if (_touchEventListener && _touchEventSelector) { (_touchEventListener->*_touchEventSelector)(this, TOUCH_EVENT_ENDED); } if (_touchEventCallback) { _touchEventCallback(this, TouchEventType::ENDED); }}
ShopPanel类:
#include "ShopPanel.h"#include "ui/CocosGUI.h"#include "Global.h"using namespace CocosDenshion;using namespace cocos2d;using namespace ui;ShopPanel::ShopPanel(){}ShopPanel::~ShopPanel(){ }bool ShopPanel::init(){ if (!Node::init()) { return false; } auto s = Director::getInstance()->getWinSize(); Layout* la = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("ui/shopPanel.json")); this->addChild(la); closeBtn = static_cast<Button*>(Helper::seekWidgetByName(la, "closeBtn")); closeBtn->addTouchEventListener(CC_CALLBACK_2(ShopPanel::closeEvent, this)); return true;}void ShopPanel::open(Node* parent){ if (parent != nullptr && !isopen) { isopen = true; parent->addChild(this); this->setScale(0); ScaleTo *scale1 = ScaleTo::create(0.2f, 1.0f); EaseBackOut *tween = EaseBackOut::create(scale1); this->runAction(tween); }}void ShopPanel::close(){ if (isopen){ isopen = false; this->removeFromParent(); }}void ShopPanel::closeEvent(Ref *pSender, Widget::TouchEventType type){ switch (type) { case Widget::TouchEventType::ENDED: this->close(); break; default: break; }}void ShopPanel::onExit(){ Node::onExit();}
调用打开函数:
void FirstScene::openShop(Ref *pSender, Widget::TouchEventType type){ switch (type) { case Widget::TouchEventType::ENDED: ShopPanel* shop = ShopPanel::create(); shop->open(this); break; }}
cocos2d-x 3.2 关闭按钮点击立马销毁自己报错
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。