void HFViewport::stepScroll(cocos2d::CCTouch* touch) { if (!mIsScrollBegan) { mIsScrollBegan = true; beginScroll(touch); } mIsProcessingScroll = true; CCPoint curTouch = touch->getLocation(); CCPoint curDiff(curTouch.x - mScrollStartPoint.x, curTouch.y - mScrollStartPoint.y); if (curDiff.getLength()>20) { isMove = true; } if( this->mTouchMode == TouchMode_Scroll ) { if (mTouchDelegate) { mTouchDelegate->onStepScroll(m_TargetNode->convertTouchToNodeSpace(touch), ccpMult(curTouch - mScrollStartPoint, 1 / this->m_TargetNode->getScale())); } curDiff = ccpMult(curDiff, OPERATION_DAMPING); CCPoint curPos = ccpAdd(mOperationStartPostition, curDiff); boundPos(curPos); CCLOG("%d,,,,,,,%d",(int)curPos.x, (int)curPos.y); CCLOGFUNCF("taget scale:%f", this->m_TargetNode->getScale()); this->m_TargetNode->setPosition(curPos); } }
void Viewport::stepScroll(Touch* touch) { if (!mIsScrollBegan) { mIsScrollBegan = true; beginScroll(touch); } mIsProcessingScroll = true; Vec2 curTouch = touch->getLocation(); Vec2 curDiff(curTouch.x - mScrollStartPoint.x, curTouch.y - mScrollStartPoint.y); if (curDiff.getLength()>20) { isMove = true; } if( this->mTouchMode == TouchMode_Scroll ) { if (mStepScrollHandler) { Vec2 point1 = m_TargetNode->convertTouchToNodeSpace(touch); Vec2 point2 = ccpMult(curTouch - mScrollStartPoint, 1 / this->m_TargetNode->getScale()); pushValueToLua(mStepScrollHandler, point1, point2); } curDiff = ccpMult(curDiff, OPERATION_DAMPING); Vec2 curPos = ccpAdd(mOperationStartPostition, curDiff); boundPos(curPos); CCLOG("%d,,,,,,,%d",(int)curPos.x, (int)curPos.y); this->m_TargetNode->setPosition(curPos); } }
void EXZoomController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent){ CCSetIterator iter = pTouches->begin(); for (; iter != pTouches->end(); iter++){ CCTouch* pTouch = (CCTouch*)(*iter); // CCPoint location = pTouch->getLocation(); _touchesDic->setObject(pTouch, CCString::createWithFormat("%d",pTouch->getID())->getCString()); CCLog("touc id %s,",CCString::createWithFormat("%d",pTouch->getID())->getCString()); } bool multitouch = _touchesDic->count() > 1; if (multitouch){ //reset history so auto scroll doesn't happen _timePointStampCounter = 0; endScroll(_firstTouch); CCArray* keys = _touchesDic->allKeys(); CCTouch *touch1 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); CCTouch *touch2 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(1))->getCString()); CCPoint pt = touch1->getLocationInView(); CCPoint pt2 = touch2->getLocationInView(); beginZoom(pt, pt2); } else { //record the point for determining velocity CCArray* keys = _touchesDic->allKeys(); // ((CCString*)keys->objectAtIndex(0))->getCString() _touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); CCTouch *touch = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); recordScrollPoint(touch); beginScroll(_node->convertToNodeSpace(touch->getLocation())); } }
void EXZoomController::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent){ bool multitouch = _touchesDic->count() > 1; if (multitouch) { CCArray* keys = _touchesDic->allKeys(); CCTouch *touch1 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); CCTouch *touch2 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(1))->getCString()); CCPoint pt1 = touch1->getLocationInView(); CCPoint pt2 = touch2->getLocationInView(); endZoom(pt1, pt2); //which touch remains? // if (touch == touch2) // beginScroll(_node->convertToNodeSpace(touch1->getLocation())); // else beginScroll(_node->convertToNodeSpace(touch2->getLocation())); } else { CCArray* keys = _touchesDic->allKeys(); CCTouch *touch = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); recordScrollPoint(touch); CCPoint pt = _node->convertToNodeSpace(touch->getLocation()); endScroll(pt); //handle double-tap zooming // if (zoomOnDoubleTap /**&& [touch tapCount] == 2*/) // handleDoubleTapAt(pt); } CCSetIterator iter = pTouches->begin(); for (; iter != pTouches->end(); iter++){ CCTouch* pTouch = (CCTouch*)(*iter); _touchesDic->removeObjectForKey(CCString::createWithFormat("%d",pTouch->getID())->getCString()); } }