본문 바로가기
프로그래밍/cocos2d-x

cocos2d-x 터치(Touch)

by -현's- 2013. 6. 1.
반응형


●스탠다드 터치 델리게이트 예제


- HelloWorldScene.h


#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__


#include "cocos2d.h"


class HelloWorld : public cocos2d::CCLayerColor

{

public:

    virtual bool init();


    static cocos2d::CCScene* scene();

    

    CREATE_FUNC(HelloWorld);

virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent* event);

virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent* event);

virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent* event);

virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent* event);



};


#endif // __HELLOWORLD_SCENE_H__





-HelloWorldScene.cpp


#include "HelloWorldScene.h"

#include "SimpleAudioEngine.h"


using namespace cocos2d;

using namespace CocosDenshion;


CCScene* HelloWorld::scene()

{

    CCScene *scene = CCScene::create();

    

    HelloWorld *layer = HelloWorld::create();


    scene->addChild(layer);


    return scene;

}


bool HelloWorld::init()

{

    if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) )

    {

        return false;

    }


    /////////////////////////////


this->setTouchEnabled(true);


    return true;

}


//처음 손가락으로 터치할때 호출된다.

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

{

CCSetIterator it=pTouches->begin();

CCTouch* touch=(CCTouch*)(*it);

CCPoint touchPoint=touch->getLocation();

CCLog("1");

}

//손가락을 화면에서 떼지 않고 드래그할때 계속 호출된다.

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

{

CCSetIterator it=pTouches->begin();

CCTouch* touch=(CCTouch*)(*it);

CCPoint touchPoint=touch->getLocation();

CCLog("2");

}

//손가락을 화면에서 떼는 순간 호출된다.

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

{

CCSetIterator it=pTouches->begin();

CCTouch* touch=(CCTouch*)(*it);

CCPoint touchPoint=touch->getLocation();

CCLog("3");

}

//시스템이 터치를 중지시키는 경우 호출된다.

void HelloWorld::ccTouchesCancelled(CCSet *pTouched, CCEvent *pEvent)

{

CCLog("4");

}

 






반응형

댓글