cocos2d-x touch事件

在.h中先申明

virtual bool ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); virtual void ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); virtual void ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); .m文件 在init方法实现touch的代理方法 CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);//设置单点触摸 //------------------------------------------------------------------------------------ void HelloWorld::ccTouchEnded(CCTouch*pTouch, CCEvent *pEvent){ CCPoint touchPoint = pTouch->locationInView(); printf("%f,%f",touchPoint.x,touchPoint.y); pSprite->setPosition(touchPoint); } void HelloWorld::ccTouchMoved(CCTouch*pTouch, CCEvent *pEvent){    printf("hhhh"); CCPoint touchPoint = pTouch->locationInView(); printf("%f,%f",touchPoint.x,touchPoint.y); }

 

posted on 2013-04-14 10:20  jack_yan  阅读(143)  评论(0)    收藏  举报