在Cocos2dx中同时使用ccTouchBegan和ccTouchesEnded

时间:2014-02-25 14:38:00

标签: cocos2d-x

我可以同时使用ccTouchBeganccTouchesEnde 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);
}

1 个答案:

答案 0 :(得分:1)

首先,您使用的是ccTouchBegan和ccTouchesEnded,您可以使用ccTouchesBegan。 要使用ccTouchesBegan和ccTouchesEnded,您需要设置:

layer->setTouchEnabled(true);

其中layer是游戏场景的主要层。