*개인 참고용으로 스크랩해온 내용입니다.
터치 이벤트 처리가 필요한 Layer 의 헤더파일에 터치 리스너 변수와 함수를 선언합니다.
cocos2d::EventListenerTouchOneByOne* _touchListener;
virtual bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
cpp 파일에서 초기화 함수 부분에 터치 이벤트 리스너를 설정하고 이벤트 디스패쳐에 등록해줍니다.
_touchListener = EventListenerTouchOneByOne::create();
_touchListener->setSwallowTouches(true);
_touchListener->onTouchBegan = CC_CALLBACK_2(TestLayer::onTouchBegan, this);
EventDispatcher* dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->addEventListenerWithSceneGraphPriority( _touchListener, this);
onTouchBegan, Moved, Ended, Cancelled 는 이전처럼 작성해주면 됩니다.
bool TestLayer::onTouchBegan(Touch* touch, Event* event)
{
Point touchPoint = touch->getLocation();
log("Default Touch began : (%f %f)",touchPoint.x, touchPoint.y);
return true;
}
'개발일지 > cocos2d-x' 카테고리의 다른 글
동적으로 파일 가져오기 (0) | 2014.02.10 |
---|---|
오브젝트 가져오기와 애니메이션 적용 (0) | 2014.02.03 |
3.0 beta 프로젝트 생성 방법 (0) | 2014.01.16 |
공통헤더 (0) | 2014.01.14 |
윈도우 사이즈 가져오기 (0) | 2014.01.14 |