报错如下:
0x10365344 (libcocos2d.dll) (9sprite.exe 中)处的第一机会异常: 0xC0000005: 写入位置 0x00000368 时发生访问冲突。
0x10365344 (libcocos2d.dll) (9sprite.exe 中)处有未经处理的异常: 0xC0000005: 写入位置 0x00000368 时发生访问冲突。
init函数修改如下
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
//auto UI = cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("MainScene.csb");
//UI->setPosition(Point(200, 200));
Node* main = CSLoader::createNode("MainScene.csb");
this->addChild(main);
dProgress = static_cast(main->getChildByName("dProgress"));
dProgress->addTouchEventListener(this, toucheventselector(HelloWorld::onClick));
return true;
}
```
Touch回调如下:
void HelloWorld::onClick(Ref*, TouchEventType type) {
switch (type) {
case TouchEventType::TOUCH_EVENT_MOVED:
dProgress->setPercent(dProgress->getPercent() + 1);
break;
}
}
```
头文件内容如下:
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "ui\CocosGUI.h"
#include "editor-support\cocostudio\CocoStudio.h"
using namespace cocos2d::ui;
using namespace cocostudio;
class HelloWorld : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
void onClick(Ref*, TouchEventType type);
LoadingBar* dProgress;
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
```
