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();
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 关闭按钮点击立马销毁自己报错的更多相关文章

  1. Eric6 右键点击生产对话框代码报错

    问题没有解决,属于菜鸟级别的孩子~~~~ 求助啊,求助!!!!!! 报告如下: Warning:An unhandled exception occurred. Please report the p ...

  2. weblogic公布的项目用途myeclipse正常启动,点击startWeblogic.cmd报错解决方案

    今天在做项目中遇到的问题.使用weblogic公布的项目,使用myeclipse正常启动,但点击startWeblogic.cmd会报错.我提出了一个class not found.楚是什么问题.后来 ...

  3. selenium+python自动化88-批量操作循环点击报错:Element not found in the cache - perhaps the page has changed since it was looked up

    前言 selenium定位一组元素,批量操作循环点击的时候会报错:Element not found in the cache - perhaps the page has changed since ...

  4. SharePoint 2013 点击"关注" 报错

    现象: 点击"关注" 报错. 解决办法: 1.确保bin文件夹下的.dll版本与web.config一致. 2.设置user porfile权限. 2.重启iis 结果如下:

  5. 【GitLab】gitlab上配置webhook后,点击测试报错:Requests to the local network are not allowed

    gitlab上配置webhook后,点击测试报错: Requests to the local network are not allowed 操作如下: 报错: 错误原因: gitlab 10.6 ...

  6. Vue项目中执行npm run dev 不报错也不显示点击的地址链接

    问题描述: 输入npm run dev 没有报错也没有显示可以点击的地址链接,如下图: 解决方法: 具体配置: autoOpenBrowser默认为false,改为true.重新 npm run de ...

  7. FCKeditor编辑器第一次点击总是报错(上传图片) 之后就好了

    错误:   Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index. FCKeditor编辑器第一次点击总是报错(上 ...

  8. vscode点击ctrl键报错Request textDocument/definition failed.

    现象 用vscode写java代码的时候突然出现,修复问题点击Ctrl时,输出窗口就打日志,报错Request textDocument/definition failed. 我百度唯一的有用线索就是 ...

  9. Java+Selenium 上传文件,点击选择“浏览文件”按钮,报错invalid argument

    Java+Selenium 上传文件,点击选择"浏览文件"按钮,报错invalid argument 解决代码: Actions action=new Actions(driver ...

随机推荐

  1. gitflow工作流程基本命令使用

    1 基础命令: 初始化: git flow init 开始新Feature: git flow feature start MYFEATURE Publish一个Feature(也就是push到远程) ...

  2. BZOJ 1003 [ZJOI2006]物流运输trans ★(Dijkstra + DP)

    题目链接 http://www.lydsy.com/JudgeOnline/problem.php?id=1003 思路 先Dijkstra暴力求出i..j天内不变换路线的最少花费,然后dp[i] = ...

  3. Django之model字段操作

    # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models import ...

  4. js中字符串与数组的相互转换

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. zuul 性能分析

    引用几篇博客, 后续整理自己心得 Zuul 性能测试 https://blog.csdn.net/u013815546/article/details/69669165 VisualVM 使用 htt ...

  7. HashMap resize代码详解(二)

    关于其中的resize方法如下: final Node<K,V>[] resize() { Node<K,V>[] oldTab = table; int oldCap = ( ...

  8. LINUX系统下APACHE中的CGI应用

    该实验环境是在APACHE的配置内容的基础上实现的! 1.安装软件: yum install  php  -y      ##安装完成后,可以在/etc/httpd/conf.d/目录下查看,有php ...

  9. Django项目的ORM操作之--模型类数据查询

    1.查询基本格式及理解: 类名.objects.[查询条件] 例如我们要查询数据库中一张表(bookinfo)的所有数据,sql语句为:select * from bookinfo, 对应模型类的操作 ...

  10. ubuntu16 chrome install

    1,download chrome.deb from : https://www.google.com/chrome/index.html 2,double click chrome.deb and ...