'Cocos2dx v3.0 click'에 해당되는 글 1건

  1. 2014.04.17 [Cocos2d-x] v3.0 click event
Game/Cocos2d-x2014.04.17 18:22

cocos2d-x v3.0에서 터치 이벤트를 구현하는 방법이 바뀐 위에 

싱글 터치 멀티 터치 모두 갖추어 진 정보가 적었 기 때문에 참고. 


어디 까지나 예문이므로, 전후의 코드 라든지 생략...

싱글 터치 

헤더 파일

Hoge.h
    bool onTouchBegan(Touch* touch, Event* event);
    void onTouchMoved(Touch* touch, Event* event);
    void onTouchEnded(Touch* touch, Event* event);
    void onTouchCancelled(Touch* touch, Event* event);

Cpp 파일

Hoge.cpp
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();

    listener->onTouchBegan = CC_CALLBACK_2(Hoge::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(Hoge::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(Hoge::onTouchEnded, this);
    listener->onTouchCancelled = CC_CALLBACK_2(Hoge::onTouchCancelled, this);

    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);

멀티 터치

헤더 파일

Hoge.h
    virtual void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *pEvent);
    virtual void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches,cocos2d::Event *pEvent);
    virtual void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *pEvent);
    virtual void onTouchesCancelled(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *pEvent);

Cpp 파일

Hoge.cpp
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchAllAtOnce::create();

    listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
    listener->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
    listener->onTouchesCancelled = CC_CALLBACK_2(HelloWorld::onTouchesCancelled, this);
    listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);

    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);

출처 : http://qiita.com/syo-sa1982/items/f6ecf4b6c2f203930eff

신고

'Game > Cocos2d-x' 카테고리의 다른 글

[Cocos2d-x] v3.0 click event  (0) 2014.04.17
Posted by Namseungil

티스토리 툴바