码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x 3.2 关闭按钮点击立马销毁自己报错

时间:2014-09-26 19:18:58      阅读:132      评论:0      收藏:0      [点我收藏+]

标签: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 关闭按钮点击立马销毁自己报错

标签:style   blog   http   color   io   os   ar   sp   div   

原文地址:http://www.cnblogs.com/as3lib/p/3994720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!