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. winmm.dll获取和设置声音

    [DllImport("winmm.dll")] private static extern int waveOutGetVolume(IntPtr hwo, out uint d ...

  2. The tilde ( ~ ) operator in JavaScript

    From the JavaScript Reference on MDC, ~ (Bitwise NOT) Performs the NOT operator on each bit. NOT a y ...

  3. 设计模式--享元模式C++实现

    1定义 使用共享对象可有效的支持大量细粒度的对象 2类图 角色分析 Flyweight抽象享元角色,一个产品的抽象,定义内部状态和外部状态的接口或者实现 ConcreteFlyweight具体享元角色 ...

  4. Java subList的使用

    1. 在看<阿里巴巴java编程手册的时候>有如下强制约束 顺便学了一下subList. java.util.List中有一个subList方法,用来返回一个list的一部分的视图. Li ...

  5. 设置了width和height的a元素在IE11与IE11以下浏览器中的不同渲染方式

    #welcomeMiddleBtn { display: block; width: 73px; height: 120px; margin: 0px auto; } <a id="w ...

  6. jersey实现跨服务器上传

    1.导入跨服务器上传文件jar文件 <dependency> <groupId>commons-io</groupId> <artifactId>com ...

  7. laravel中设置表单的方式,以及获取表单的提交的数据

  8. 基于C#在Mongodb的Skip-Limit和Where-Limit的分页对比 并且含mongodb帮助类的源码

    最近在设计的日志服务中需要用到Mongodb这个Nosql数据库(不知道Mongodb的点我),由于是用于纯存日志,而且日志量巨大,百万千万级的,所以需要用到它的分页查询. 不过LZ也是刚刚接触这个数 ...

  9. 一、html <!doctype>标签

    一.html <!doctype>标签 定义和用法 <!DOCTYPE> 声明必须是 HTML 文档的第一行,位于 <html> 标签之前. <!DOCTYP ...

  10. SSH服务:packet_write_wait: Connection to 67.218.143.160 port 22: Broken pipe错误处理

    1.在~/.ssh/config配置文件中添加 IPQoS lowdelay throughput 2.在/etc/ssh/ssh_config配置文件中添加 IPQoS lowdelay throu ...