cocos2d-x 3.2 關閉按鈕點擊立馬銷毀自己報錯

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   sp   div   

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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.