在.h中声明:
virtual void registerWithTouchDispatcher(void); virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
this->setTouchEnabled(true);
void DragScene::registerWithTouchDispatcher(void){ CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } bool DragScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { mBullet->setPosition(ccp(pTouch->getLocation().x , pTouch->getLocation().y)); return true; } void DragScene::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) { mBullet->setPosition(ccp(pTouch->getLocation().x , pTouch->getLocation().y)); } void DragScene::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { } void DragScene::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) { }
效果图:
转载请注明出处:http://blog.csdn.net/Vestigge