2014년 7월 7일 월요일

자동로그인처럼 바로 화면 전환되게 하기


init() 에다가 replaceScene을 쓸 수 없다.

따라서 일정시간 후에 어떤 함수가 불러지게 선언해두고

그 어떤 함수 안에 replaceScene을 넣어두면 원하는 기능을 사용할 수 있다/



In .h file you declare
void myModification(float dt);
In .cpp file
this->scheduleOnce(schedule_selector(&MyClass::myModification), 10.0f);

void Myclass::myModification(float dt)
{
//your code
}


출처 : stackoverflow
http://stackoverflow.com/questions/20206681/can-i-use-the-cocos2d-x-scheduler-to-delay-a-single-line-of-code

2014년 7월 3일 목요일

NULL 에러가 뜨는 경우

NULL 에러
case 정리


- init()함수에서 return true;를 누락했을 경우 CCSprite가 NULL로 뜰 수도 있다.

-참조한 파일이 없거나, 참조 이름이 틀릴 경우
ex) CCSprite* img = CCSprite::create("background.png");

-
-
--
-
--


많은 케이스가 있지만 앞으로 차차 정리하기로,.

2014년 2월 20일 목요일

isometric zig

http://www.theoworlds.com/theoworldsbuilder/documentation/mapgraphics.html

2014년 2월 12일 수요일

PanZoomLayer 참고 링크


CCLayerPanZoom

1.
https://gist.github.com/growingdever/8535614


2.
http://www.cocos2d-x.org/forums/6/topics/5430

2번을 참고해서 한국개발자이 1번을 만들었다고 함.

2014년 2월 3일 월요일

메뉴 터치 구현

helloworld.cpp에서


#include "HelloWorldScene.h"



USING_NS_CC;

CCScene* HelloWorld::scene()
{
   
    CCScene *scene = CCScene::create();
    
    HelloWorld *layer = HelloWorld::create();


    scene->addChild(layer);

    return scene;
}







bool HelloWorld::init()
{
       if ( !CCLayer::init() )
    {
        return false;
    }
    
    //터치
    setTouchEnabled(true);
    
    
    //사이즈 가져오기
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    
    
    
    
    //해변 배경 테스트 
    
    CCSprite* bg_aqua = CCSprite::create("aqua.jpg");
    bg_aqua->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(bg_aqua, -2);

    
    
    
    //타일맵 깔기
    
    CCTMXTiledMap *map = CCTMXTiledMap::create("kiwanTest4.tmx");
    map->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
    map->setAnchorPoint(ccp(0.5f, 0.5f));
    map->setScale(0.65f);
    addChild(map,-1);
    
    
    //플레이 화면 깔기
    CCSprite* pSprite = CCSprite::create("pg2_non.png");
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(pSprite, 0);
    
    
    
    //메뉴 버튼 만들기
    
    CCMenuItemImage* bt_RUN =
    CCMenuItemImage::create("running_bt.png", "running_bt2.png",this, menu_selector(HelloWorld::goToRun));
    
    
    
    
    CCMenu* menuMain = CCMenu::create(bt_RUN,NULL);
    
    
    
    
    //버튼 위치를 바꾸려면 ccMenu위치를 바꿔야
    menuMain->setPosition(ccp(100.0f , 100.0f ));
    
    addChild(menuMain,1);
    
    
    
    
    
    
    return true;
}




void HelloWorld::goToRun(CCObject* pSender){
    
    
    CCLog("goToRun Runs....");
    CCScene* runScene = ExerciseScene::rScene();
    CCTransitionScene* pTran = CCTransitionFade::create(1.5f, runScene);
    CCDirector::sharedDirector()->replaceScene(pTran);
    
    
}




void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
    
}

void HelloWorld::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
    
    
    
    
}

void HelloWorld::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
}

void HelloWorld::ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *event){
    
    
}





2014년 2월 2일 일요일

멀티터치 테스트 방법

xcode

시뮬레이터 상에서

옵션키를 누르면 동그란 원 두개가 뜨면서 멀티터치처럼 만들어줘서
 멀티터치를 테스트해볼 수 있다.

2014년 1월 27일 월요일

해상도 문제

[AppDelegate.cpp]에서


#include "AppDelegate.h"
#include "HelloWorldScene.h"


typedef struct tagResource
{
    cocos2d::CCSize size;
    char directory[100];
} Resource;

static Resource resource1 = { cocos2d::CCSizeMake(480, 320),   "iphone3" };
static Resource resource2 = { cocos2d::CCSizeMake(960, 640),   "iphone4" };
static Resource resource3 = { cocos2d::CCSizeMake(1024, 768),  "ipad"   };
static Resource resource4 = { cocos2d::CCSizeMake(2048, 1536), "ipadhd" };

static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);


USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {

    
    
    
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
    
    pEGLView->setDesignResolutionSize(designResolutionSize.width,
                                      designResolutionSize.height,
                                      kResolutionNoBorder);

    



해상도 문제 해결! ㅎㅎ

맵 이동 (getDelta, ccTouchMoved)







bool HelloWorld::init(){
   
...
//맵 불러오기

    CCTMXTiledMap* tmap = CCTMXTiledMap::create("TestDesert.tmx");

    this->addChild(tmap, 0, 11);   //이름, zorder, tag

...


}


//터치로 맵 움직이기 


void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent* event)
{


    CCPoint diff = pTouch->getDelta();
    
    CCNode* node = this->getChildByTag(11);
    CCPoint currentPos = node->getPosition();
    
    CCPoint newPos = ccpAdd(currentPos, diff);
    
    if (newPos.x < -160) {
        newPos.x = -160;
    }
    if (newPos.x > 0) {
        newPos.x = 0;
    }
    newPos.y = 0;
    
    node->setPosition( newPos );
    
    
}

멀티터치 세팅

[AppController.mm]에서

----------------------------------------

// cocos2d application instance
static AppDelegate s_sharedApplication;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    ...



    // Use RootViewController manage EAGLView 
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    viewController.view = __glView;


//다음을 추가
    
    [__glView setMultipleTouchEnabled:YES];
    
    
    // Set RootViewController to window
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        // warning: addSubView doesn't work on iOS6
        [window addSubview: viewController.view];
    }
    else
    {
        // use this method on ios6
        [window setRootViewController:viewController];
    }
    ...

    return YES;
}


----------------------------------------------

[HelloWorldScene.cpp]에서


bool HelloWorld::init()
{
   
    if ( !CCLayer::init() )
    {
        return false;
    }

...    


//다음을 추가
    CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);

...
    
    return true;
}

---------------------------------------------
[helloWorld.h]에서


    void ccTouchesBegan(CCSet* touches, CCEvent* event);
    void ccTouchesMoved(CCSet* touches, CCEvent* event);
    void ccTouchesEnded(CCSet* touches, CCEvent* event);



Cocos2d-x 관련 각종 링크들

1. Cocos2d-x Reference
cocos2d-x에서 제공하는 레퍼런스. 중간에 버전을 바꾸면 해당 버전의 레퍼런스로 이동한다. ex : V3alpha1, V2.2.1
http://www.cocos2d-x.org/reference/native-cpp/V2.2.1/index.html

2. Cocos2d-x 사용자 모임
'시작하세요! cocos2d-x 프로그래밍' 저자가 운영하는 네이버 카페. 비교적 활발한 교류가 이루어지고 있다.
http://cafe.naver.com/cocos2dxusers#

3. Cocos2d-x 모바일 인디 개발자 모임
'-만들면서 이해하는- 실전! Cocos2d-x 3.x 게임 프로그래밍' 저자가 운영하는 다음 카페. 내용은 적은 편이나 Q&A를 저자가 꼬박꼬박 달아 주셔서 유용하다.
http://cafe.daum.net/cocos2d-x

4.. Cocos2d-x 개인 블로그
Cocos2d-x Tutorial 이라는 주제로 기초적인 cocos2d-x를 다룸.
(Sprite, Collision, Sound)
http://cocos2dx.tistory.com/category/cocos2d-x%20Tutorial

5. 현's 블로그
Cocos2d-x뿐 아니라 많은 주제에 대해 포스팅 중.
(에러처리, 메뉴, 장면전환 등 기초적인 cocos2d-x 에 대해 모두 다루고 있다.)
http://hyunssssss.tistory.com/category/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D/cocos2d-x

6. 뽀삐 블로그
드래곤빌리지, 몬스터 월드 개발자의 블로그.
cocos2d-x에 관한 각종 강좌가 있다.
http://blog.naver.com/PostList.nhn?blogId=dlehddus84

7. 궁극의 잡 블로그
말 그대로 잡 블로그. cocos2d-x관한 설명이 많은 편. 특히 버전별로 소개된 부분이 있어 참고할 부분이 많을 듯.
http://zzaps.tistory.com/

8. Singleton's Programming, Game.. and Fantasy.
게임개발 탭을 보면 cocos2d-x 관련자료가 많음.
http://singleton.tistory.com/category/%EA%B2%8C%EC%9E%84%EA%B0%9C%EB%B0%9C

9. 철이의 컴노리
게임개발팁에 cocos2d-x관련 자료가 있고, 다른 부분도 참고할 만함.(아이폰, 안드로이드 등)
http://skyfe.tistory.com/category/%EA%B2%8C%EC%9E%84%EA%B0%9C%EB%B0%9C%ED%8C%81

10.tilemap tutorial
타일맵을 어떻게 하는지 잘 나와있는듯. 교재에서도 이 사이트를 참고해서 만든 것 같다.
http://www.raywenderlich.com/39113/cocos2d-x-tile-map-tutorial-part-1/

11. VLink Blog
애니메이션 타일에 관한 자료가 있다.
http://hashs.tistory.com/category/%EC%BD%94%EC%BD%94%EC%8A%A42D-X

12. ULSANSTAR
다양한 cocos2d-x관련 링크 제공. 시간될때마다 확인할것.
http://blog.naver.com/PostList.nhn?blogId=ulsanstar00

13. 터프 프로그래머 블로그
cocos2d-x 관련 자료 및 다양한 자료 있음.
http://growingdever.tistory.com/category/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D/Game

2014년 1월 26일 일요일

메뉴 만들기

태그 지정을 해야 카테고리를 만들 수 있다니.

플레이 화면 테스트




플레이 화면

화면전환



화면 전환하는 코드

    CCScene* runScene = ExerciseScene::rScene();
    CCTransitionScene* pTran = CCTransitionFade::create(1.5f, runScene);

    CCDirector::sharedDirector()->replaceScene(pTran);