移动图片与双击判断

void ImageLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) { CCLog(“ccTouchesMoved”);
CCTouch* touch=(CCTouch*)pTouches->anyObject();
CCSprite* sprite=(CCSprite*)this->getChildByTag(1);

CCPoint imagePostion=sprite->getPosition();

CCPoint ccp1=touch->getLocation();
CCPoint ccp2=touch->getPreviousLocation();

imagePostion.x=imagePostion.x+ccp1.x-ccp2.x;
imagePostion.y=imagePostion.y+ccp1.y-ccp2.y;

sprite->setPosition(imagePostion);
}

cocos2dx中只能判断单击,所以双击,实际上是验证两次点击时间小于300ms

static long lastClickTime=0;

long now=millisecondNow();
if(now-lastClickTime<300){
doubleClick();
}

lastClickTime=now;

// 以下函数用来获得毫秒值。

long ImageLayer::millisecondNow()
{
struct cc_timeval now;
CCTime::gettimeofdayCocos2d(&now, NULL);
return (now.tv_sec * 1000 + now.tv_usec / 1000);
}

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>