I have created coding for single and double click. I want to prevent single click event when making double click.
When making single click, the shape will changed circle to rectangle and vice versa.
When making double click, the shape is destroyed.
While making double click, the single click event is also executed. I want to prevent single click event at that time.
Any idea should help me.
Here the coding
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);
}
And the mouse up event,
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();
}
}
}
}
}