我可以同时使用ccTouchBegan
和ccTouchesEnde
d吗?
当我尝试在ccTouchBegan
中添加操作时,我发现ccTouchesEnded
未被调用。任何人都可以向我解释如何使用触摸事件吗?
我的一些代码
bool GameplayScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
CCActionInterval* actionBy = CCRotateBy::create(1, 180);
weapon->runAction(CCSequence::create(actionBy, NULL, NULL));
location = pTouch->getLocation();
shootBullet();
this->schedule(schedule_selector(GameplayScene::shootBullet), 1.0);
return true;
}
void GameplayScene::ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event){
this->unschedule(schedule_selector(GameplayScene::shootBullet));
}
void GameplayScene::registerWithTouchDispatcher(void) {
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + 1, true);
}
答案 0 :(得分:1)
首先,您使用的是ccTouchBegan和ccTouchesEnded,您可以使用ccTouchesBegan。 要使用ccTouchesBegan和ccTouchesEnded,您需要设置:
layer->setTouchEnabled(true);
其中layer是游戏场景的主要层。