void EXZoomController::endScroll(CCPoint pos) { unschedule(schedule_selector(EXZoomController::updateTime)); //Only perform a velocity scroll if we have a good amount of history if (_timePointStampCounter > 3) { //calculate velocity CCPoint velocity = ccpMult(getHistoricSpeed(), swipeVelocityMultiplier * _node->getScale()); //Make sure we have a reasonable speed (more than 5 pts away) if (ccpLengthSQ(velocity) > 5*5) { //caculate position of swipe action CCPoint newPos = ccpAdd(_node->getPosition(), velocity); newPos = boundPos(newPos); //create the action CCMoveTo* moveTo = CCMoveTo::create(scrollDuration, newPos); CCEaseOut* ease = CCEaseOut::create(moveTo, 3); CCLOG("stop 1"); //unconditional stop; cocos handles this properly _node->stopAction(_lastScrollAction); _node->runAction(ease); //release our last action since we retain it below if (_lastScrollAction) { _lastScrollAction->release(); _lastScrollAction = NULL; } CCLOG("stop end"); _lastScrollAction = ease; _lastScrollAction->retain(); } } }
void HFViewport::applyZoom(float newZoom) { if(!allowZoom){ return; } float oldScale = this->m_TargetNode->getScale(); this->m_TargetNode->setScale(newZoom); CCPoint newCenter(mNSZoomCenter); newCenter = this->m_TargetNode->convertToWorldSpace(newCenter); CCPoint centerDif = ccpSub(mWSZoomCenter, newCenter); cocos2d::CCPoint pos = ccpAdd(m_TargetNode->getPosition(), centerDif); CCLOGFUNCF("pos.x=%f, pos.y=%f, centerDif.x=%f, y=%f", pos.x, pos.y, centerDif.x, centerDif.y); if(boundPos(pos)) { this->m_TargetNode->setPosition(pos); mCurZoomScale = newZoom; CCLOGFUNCF("new mCurZoomScale=%f", mCurZoomScale); } else { this->m_TargetNode->setScale(oldScale); mCurZoomScale = oldScale; CCLOGFUNCF("old mCurZoomScale=%f", mCurZoomScale); } }
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::applyZoom(float newZoom) { if(!allowZoom){ return; } float oldScale = this->m_TargetNode->getScale(); this->m_TargetNode->setScale(newZoom); Vec2 newCenter(mNSZoomCenter); newCenter = this->m_TargetNode->convertToWorldSpace(newCenter); Vec2 centerDif = ccpSub(mWSZoomCenter, newCenter); Vec2 pos = ccpAdd(m_TargetNode->getPosition(), centerDif); if(boundPos(pos)) { this->m_TargetNode->setPosition(pos); mCurZoomScale = newZoom; } else { this->m_TargetNode->setScale(oldScale); mCurZoomScale = oldScale; } }
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 HFViewport::applyPos(CCPoint position) { CCPoint newPosition = ccpAdd(this->m_TargetNode->getPosition(), position); if (boundPos(newPosition)) { this->m_TargetNode->setPosition(newPosition); mWSZoomCenter = ccpAdd(mWSZoomCenter, position); mNSZoomCenter = this->m_TargetNode->convertToNodeSpace(mWSZoomCenter); } }
void EXZoomController::centerOnPoint(CCPoint pt, float duration, float rate) { CCPoint mid = _node->convertToNodeSpace(ccpMidpoint(_winTr, _winBl)); CCPoint diff = ccpSub(mid, pt); CCPoint final = boundPos(ccpAdd(_node->getPosition(), diff)); CCMoveTo* moveTo = CCMoveTo::create(duration, final); CCEaseOut* ease = CCEaseOut::create(moveTo, rate); _node->runAction(ease); }
void HFViewport::updatePosition(CCPoint pos, bool animate, float time, bool bound) { //user interface to boundPos basically m_TargetNode->stopAllActions(); if (bound) { boundPos(pos); } if(!animate){ m_TargetNode->setPosition(pos); }else{ m_TargetNode->runAction(CCMoveTo::create(time, pos)); } }
void HFViewport::centOnPoint(cocos2d::CCPoint curTouch, bool useTween){ mIsProcessingScroll = true; CCPoint visibleTopRight(CCDirector::sharedDirector()->getWinSize().width, CCDirector::sharedDirector()->getWinSize().height); curTouch.x = visibleTopRight.x/2- curTouch.x*m_TargetNode->getScale(); curTouch.y = visibleTopRight.y/2- curTouch.y*m_TargetNode->getScale(); boundPos(curTouch); if(useTween){ m_TargetNode->runAction(CCMoveTo::create(0.3, curTouch)); }else{ m_TargetNode->setPosition(curTouch); } }
void EXZoomController::updatePosition(CCPoint pos) { //user interface to boundPos basically pos = boundPos(pos); _node->setPosition(pos); }