2014년 4월 2일 수요일

cocos2d-x Keypad 자동 열기





EditBox가 포함된 Scene을 열었을 때, 특정 EditBox를 터치 하지 않은 상태에서 해당 EditBox에 입력할 수 있게 키보드가 자동으로 열리도록 하는 방법.

cocos2d-x 3.0 rc0
/extensions/GUI/CCEditBox/하위의 CCEditBox.h, CCEditBox.cpp에 다음과 같은 코드를 추가한다.

CCEditBox.h
void openKeyboard();

CCEditBox.cpp
void EditBox::openKeyboard()
{
      _editBoxImpl->openKeyboard();
}

그리고 위 메서드를 적용하려는 Scene에서 호출하면 도니다.

예 : editbox->openKeyboard()

2014년 3월 18일 화요일

Layer parameters for initializing 레이어에 파라미터 넘겨주는 방법 - cocos2d-x 3.0

HomeScene에 파라미터가 포함된 HomeLayer를 추가하는 방법

HomeScene.h
#ifndef __Fortune__HomeScene__
#define __Fortune__HomeScene__

#include "cocos2d.h"

class HomeScene:public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();
};

#endif

HomeScene.cpp
#include "HomeScene.h"
#include "HomeLayer.h"

cocos2d::Scene* HomeScene::createScene()
{
    auto scene = cocos2d::Scene::create();
    auto layer = HomeLayer::createWithScenetype(2);
    
    scene->addChild(layer);
    
    return scene;
}




HomeLayer.h
#include "cocos2d.h"
class HomeLayer:public cocos2d::Layer
{
public:
    static cocos2d::Layer* createWithScenetype(int st);
    bool init(int st);

private:
    int _type;    
};


HomeLayer.cpp
#include "HomeLayer.h"
Layer* HomeLayer::createWithScenetype(int st)
{
    auto layer = new HomeLayer();
    if (layer && layer->init(st))
    {
        layer->autorelease();
        return layer;
    }
    return NULL;
}

bool HomeLayer::init(int st)
{
    if (!Layer::init())
    {
        return false;
    }
    
    _type = st;
    
    log("scene type : %d", _type);
    }
    
    return true;
}

2014년 1월 3일 금요일

vim에서 make명령어 사용방법

일단 다음과 같은 두 파일이 있다고 가정한다.

sub.c

#include <stdio.h>
void sub()
{
    printf("sub.c\n");
}

hello.c

#include <stdio.h>
void sub()

int main()
{
    sub();
    printf("Hello World!\n");
}






Makefile의 생성

vi Makefile (vi로 새로운 Makefile 파일을 생성한다.)

CC=gcc -c
LK=gcc -o

all:hello                  // 파일 hello가 있으면 종료 없으면 hello: target으로 이동

hello: hello.o sub.o       // hello.o, sub.o파일이 있으면 $(LK)명령 실행, 없으면 hello.o: 또는 sub.o: target으로 이동
    $(LK) hello hello.o sub.o
hello.o:hello.c
    $(CC) hello.c
sub.o:sub.c
    $(CC) sub.c

clean:
    rm -rf *.o hello       // 현재 디렉토리에 .o파일과 hello 제거

위 Makefile에서 $(LK), $(CC), rm앞과 같이 명령어 앞에 반드시 tab키가 들어가야 한다.




Makefile의 사용

컴파일 방법
make
또는
make all

제거 방법
make clean