zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    Android 逐帧动画isRunning 一直返回true的问题
    android动画学习
    android信号强度
    在代码中创建Drawable资源
    通过ComponentName获取相应的Widget
    EditText和输入法相关的问题
    Android 沉浸式状态栏
    安防设置功能出现的错误
    自定义seekbar
    android 新控件 AppBarLayout 使用
  • 原文地址:https://www.cnblogs.com/as3lib/p/3994720.html
Copyright © 2011-2022 走看看