Post

onTouchBegan replaceScene 에러

아직도 정확한 에러 원인은 모르겠지만 기록.A, B 씬 이동을 왔다갔다 하는데 이 때 배경을 터치하면 다른 화면으로 이동한다.유독 B씬에서 A로 넘어갈때 크래시가 났다. 디버그가 안된다고 스택도 안뜨고..그러다가 간간히 아래와 처럼 떴다.

baseproject.exe![thunk]:GameScene::`vcall'{688,{flat}}' }'() C++
  libcocos2d.dll!std::_Func_class<int,enum cocos2d::ui::Widget::FocusDirection,class cocos2d::ui::Widget *>::operator()(enum cocos2d::ui::Widget::FocusDirection,class cocos2d::ui::Widget *) C++
  libcocos2d.dll!cocos2d::EventDispatcher::EventListenerVector::~EventListenerVector(void) C++
  libcocos2d.dll!std::_Hash<class std::_Umap_traits<float,class std::vector<class cocos2d::Node *,class std::allocator<class cocos2d::Node *> >,class std::_Uhash_compare<float,struct std::hash<float>,struct std::equal_to<float> >,class std::allocator<struct std::pair<float const ,class std::vector<class cocos2d::Node *,class std::allocator<class cocos2d::Node *> > > >,0> >::_Range_eraser::_Bump_erased(void) C++
  libcocos2d.dll!std::_Func_class<float,float>::operator()(float) C++
> libcocos2d.dll!cocos2d::EventDispatcher::dispatchTouchEventToListeners(class cocos2d::EventDispatcher::EventListenerVector *,class std::function<bool (class cocos2d::EventListener *)> const &) C++
  libcocos2d.dll!cocos2d::EventDispatcher::dispatchTouchEvent(class cocos2d::EventTouch *) C++
  libcocos2d.dll!cocos2d::EventDispatcher::dispatchEvent(class cocos2d::Event *) C++
  libcocos2d.dll!cocos2d::GLView::handleTouchesBegin(int,int * const,float * const,float * const) C++
  libcocos2d.dll!cocos2d::GLViewImpl::onGLFWMouseCallBack(struct GLFWwindow *,int,int,int) C++
  libcocos2d.dll!cocos2d::GLFWEventHandler::onGLFWMouseCallBack(struct GLFWwindow *,int,int,int) C++
  libcocos2d.dll!__glfwInputMouseClick() C
  libcocos2d.dll!_glfwGetWin32Window() C
  user32.dll!764215fb() 알 수 없음
  [아래 프레임이 누락 및/또는 올바르지 않음, user32.dll에 대해 로드된 기호가 없음]
  [외부 코드]

dispatchTouchEvent 라고 적혀 있으니까 터치 이벤트에 관한 건가 싶어서

씬 생성 부분을 빨리 만들어주기도 하고... 여러모로 해봤으나 실패.그냥 버튼으로 하자고 해서 했더니 에러가 없었다.아무곳에나 터치X 그냥 버튼으로 하는게 답인가 싶다.

Post

Cocos2dx Change Scene 화면전환 예제

replaceScene: 화면이 전환될 때 메모리를 해제한다. 메모리가 해제되긴 하지만 메모리를 해제해서 이전 상태값 저장이 되지 않는다.

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

USING_NS_CC;


class HelloWorld : public LayerColor
{
public:
    static cocos2d::Scene* createScene();
    
    virtual bool init();
    
    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);

    void changeScene(Ref* sender);
};

#endif // __HELLOWORLD_SCENE_H__

HelloWorld.cpp

#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "GameScene.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();

    auto layer = HelloWorld::create();
    scene->addChild(layer);

    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    if (!LayerColor::initWithColor(Color4B(0, 0, 255, 255))) {
        return false;
    }

    auto item = MenuItemFont::create("Game Scene", CC_CALLBACK_1(HelloWorld::changeScene, this));

    auto menu = Menu::create(item, NULL);
    menu->alignItemsHorizontally();
    this->addChild(menu);
   
    return true;
}

void HelloWorld::changeScene(Ref* sender) {
    Director::getInstance()->replaceScene(GameScene::createScene());
}

GameScene.h

#ifndef __OTHER_SCENE_H__
#define __OTHER_SCENE_H__

#include "cocos2d.h"

USING_NS_CC;

class GameScene : public Layer {
public:
	static Scene* createScene();

	virtual bool init();
	CREATE_FUNC(GameScene);
};

#endif

GameScene.cpp

#include "GameScene.h"

Scene* GameScene::createScene() {
	auto scene = Scene::create();

	auto layer = GameScene::create();
	scene->addChild(layer);

	return scene;
}

bool GameScene::init() {
	if (!Layer::init()) {
		return false;
	}

	return true;
}

Post

Cocos2dx 소멸자 CCLog 에러

Cocos2dx 소멸자 CCLog 에러

이해할 수 없는 에러가 떴다...

왜 소멸자를 찾지 못하죠?

오류	LNK2019	"void __cdecl cocos2d::CCLog(char const *,...)"
(?CCLog@cocos2d@@YAXPBDZZ)"public: virtual __thiscall HelloWorld::~HelloWorld(void)"
(??1HelloWorld@@UAE@XZ) 함수에서 참조되는 확인할 수 없는 외부 기호
vg	H:\CocosProject\vg\HelloWorldScene.obj	1

근데 내가 자세히 안봐서...

소멸자를 못찾은게 아니라 CCLog 함수를 못찾은 것...

CCLOG 헤더 파일 CCPlatformMacros.h 를 include 하거나

cocos2d.h 헤더추가

Post

VSCODE 자동완성 끄기

1. Ctrl+, 

2. intellisense 검색. 보이는 모든 체크 박스 해제

3. 귀찮다면 설정 json 파일 열기 (문서에 빙그르르 돌아가는 화살표)에다가 아래코드 붙여넣기

  "explorer.compactFolders": false,
    "explorer.confirmDragAndDrop": false,
    "editor.suggest.showConstants": false,
    "editor.suggest.showConstructors": false,
    "editor.suggest.showCustomcolors": false,
    "editor.suggest.showDeprecated": false,
    "editor.suggest.showEnumMembers": false,
    "editor.suggest.showEnums": false,
    "editor.suggest.showEvents": false,
    "editor.suggest.showFields": false,
    "editor.suggest.showFiles": false,
    "editor.suggest.showFolders": false,
    "editor.suggest.showFunctions": false,
    "editor.suggest.showInterfaces": false,
    "editor.suggest.showIssues": false,
    "editor.suggest.showKeywords": false,
    "editor.suggest.showMethods": false,
    "editor.suggest.showModules": false,
    "editor.suggest.showOperators": false,
    "editor.suggest.showProperties": false,
    "editor.suggest.showReferences": false,
    "editor.suggest.showSnippets": false,
    "editor.suggest.showStructs": false,
    "editor.suggest.showTypeParameters": false,
    "editor.suggest.showUnits": false,
    "editor.suggest.showUsers": false,
    "editor.suggest.showValues": false,
    "editor.suggest.showVariables": false,
    "editor.suggest.showWords": false,
    "editor.suggest.showClasses": false,
    "editor.suggest.showColors": false

 

Post

c++ 알 수 없는 재정의 지정자입니다

c++ 알 수 없는 재정의 지정자입니다라는 에러가 떴다.

Size test;

라고 헤더에 선언하고 그대로 cpp에서 사용하는데 말이다.

class가 cocos2d::Layer 상속받고 있었는데 설마 cocos2d::Layer 안에 test라는 변수가 있겠냐고....

근데도 계속 c++ 알 수 없는 재정의 지정자입니다 라는 에러가 떴다ㅠㅠ

당연히 이름이 틀릴리는 없고....

그래서 혹시나 싶어 test 변수를 사용하는 곳에 마우스를 갖다대니 <error-type>이라는 팁창이 떴다.

Size가 어느 class에 Size인지 인지를 하지 못한 모양.

보니까 내가 USING_NS_CC; 라고 선언을 안해봐서

어디의 Size 클래스 명을 쓰는 건지 알 수 없던 모양이었다.

USING_NS_CC; 추가하고 해결.

아니면 Size에 namespace를 추가해도 해결된다.

▲ top