●스탠다드 터치 델리게이트 예제
- 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"); }
|
'프로그래밍 > cocos2d-x' 카테고리의 다른 글
cocos2d-x CCUserDefault (0) | 2013.06.01 |
---|---|
cocos2d-x 스케줄 (0) | 2013.06.01 |
cocos2d-x 심플오디오엔진(SimpleAudioEngine) (0) | 2013.05.31 |
cocos2d-x 애니메이션 (0) | 2013.05.31 |
cocos2d-x 트랜지션(Transition) 추가,삭제,교체 (0) | 2013.05.30 |
댓글