cocos2dx 在button回调函数里removeFromParent崩溃

前端之家收集整理的这篇文章主要介绍了cocos2dx 在button回调函数里removeFromParent崩溃前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
找到UIWidget.cpp文件:然后做以下修改(最新版本貌似已经做出了修正):
void Widget::pushDownEvent()
{
	this->retain();
    if (_touchEventCallback) {
        _touchEventCallback(this,TouchEventType::BEGAN);
    }
    
    if (_touchEventListener && _touchEventSelector)
    {
        (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_BEGAN);
    }
	this->release();
}

void Widget::moveEvent()
{
	this->retain();
    if (_touchEventCallback) {
        _touchEventCallback(this,TouchEventType::MOVED);
    }
    
    if (_touchEventListener && _touchEventSelector)
    {
        (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_MOVED);
    }
	this->release();
}

void Widget::releaseUpEvent()
{
    this->retain();
    if (_touchEventCallback) {
        _touchEventCallback(this,TouchEventType::ENDED);
    }
    
    if (_touchEventListener && _touchEventSelector)
    {
        (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_ENDED);
    }
	this->release();
}

void Widget::cancelUpEvent()
{
	this->retain();
    if (_touchEventCallback)
    {
        _touchEventCallback(this,TouchEventType::CANCELED);
    }
   
    if (_touchEventListener && _touchEventSelector)
    {
        (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_CANCELED);
    }
    this->release();
}
原文链接:https://www.f2er.com/cocos2dx/345869.html

猜你在找的Cocos2d-x相关文章