单击并双击

时间:2013-10-10 11:34:03

标签: box2d cocos2d-x

我已经为单击和双击创建了编码。我想在双击时阻止单击事件。

单击时,形状将变为圆形,反之亦然。

双击时,形状会被破坏。

双击时,也会执行单击事件。我想在那时阻止单击事件。

任何想法都应该帮助我。

这里是编码

void HelloWorld::ccTouchesEnded(CCSet *touch, CCEvent *pEvent)
{
   CCTouch* myTouch = (CCTouch*)touch->anyObject();
   CCTime::gettimeofdayCocos2d(&endTime, NULL);
   duration = CCTime::timersubCocos2d(&startTime, &endTime); //duration of tap in milliseconds
   finalPosition = myTouch->getLocation();
   float distance = distanceBetweenPoints(finalPosition,initialPosition);

   if (duration<kTapMaxDuration && distance <kTapMaxDistance)
   {
      taps++;
   }
   else
     taps=0;

    CCPoint touchLocation=myTouch->locationInView();
touchLocation=CCDirector::sharedDirector()->convertToGL(touchLocation);
    CCPoint nodePosition = this->convertToNodeSpace(touchLocation);
this->mouseUp(b2Vec2(nodePosition.x/kPhysicsPTMRatio,nodePosition.y/kPhysicsPTMRatio));
    CCTime::gettimeofdayCocos2d(&startTime, NULL);
 }

鼠标注册事件,

 void HelloWorld::mouseUp(b2Vec2 p)
 {
     b2AABB aabb;
 b2Vec2 d = b2Vec2(0.001f, 0.001f);
 aabb.lowerBound = p - d;
 aabb.upperBound = p + d;

 MyQueryCallback callback(p);

 world_->QueryAABB(&callback, aabb);

     if (callback.m_fixture)
 {
       b2Body *body = callback.m_fixture->GetBody();
       BodyNode *node = (BodyNode*) body->GetUserData();
   if( node && node->isTouchable_ )
       {
        if( (dynamic_cast<Shape1*>(node) != NULL))
        {
            if (taps == 1)
            {
                this->removeB2Body(body);
            }
            else if(taps < 1)
            {
                dynamic_cast<Shape1*>(node)->toggleShape();
            }
        }
    }
}

}

0 个答案:

没有答案