void Viewport::scrollBy(const Vec2& targetPoint, CallFunc* callbackFunc,float time) { unscheduleAll(); mIsProcessingScroll = true; do { this->mTouchMode = TouchMode_Fling; Vec2 curPos = this->m_TargetNode->getPosition(); Vec2 targetPos = ccpSub(curPos,targetPoint); Size winsize = Director::getInstance()->getWinSize(); if (targetPos.x >0.0f) { targetPos.x = curPos.x; } if (targetPos.x <winsize.width-mMapSize.width*this->m_TargetNode->getScaleX()){ targetPos.x = winsize.width-mMapSize.width*this->m_TargetNode->getScaleX(); } if (targetPos.y >0.0f) { targetPos.y = curPos.y; } if (targetPos.y <winsize.height-mMapSize.height*this->m_TargetNode->getScaleY()){ targetPos.y =winsize.height-mMapSize.height*this->m_TargetNode->getScaleY(); } if(time <0.0f) { this->m_TargetNode->setPosition(targetPos); return; } MoveBy* moveTo = MoveBy::create(time, targetPos); EaseOut* ease = EaseOut::create(moveTo, 3); ease->setTag(FLINGACTION_TAG); this->m_TargetNode->runAction(CCRepeat::create(CCSequence::create(ease, callbackFunc, NULL), 1)); this->mTouchMode = TouchMode_Fling; } while(0); mIsProcessingScroll = false; }
// 移动场景到指定的坐标点 void Viewport::scrollTo(const Vec2& targetPoint, CallFunc* callbackFunc, bool Flying) { unscheduleAll(); mIsProcessingScroll = true; do { this->mTouchMode = TouchMode_Fling; Vec2 curPos = this->m_TargetNode->getPosition(); Vec2 targetPos = targetPoint; Size winsize = Director::getInstance()->getWinSize(); if (targetPos.x >0.0f) { targetPos.x = curPos.x; } if (targetPos.x <winsize.width-mMapSize.width*this->m_TargetNode->getScaleX()){ targetPos.x = winsize.width-mMapSize.width*this->m_TargetNode->getScaleX(); } if (targetPos.y >0.0f) { targetPos.y = curPos.y; } if (targetPos.y <winsize.height-mMapSize.height*this->m_TargetNode->getScaleY()){ targetPos.y =winsize.height-mMapSize.height*this->m_TargetNode->getScaleY(); } if (Flying) { MoveTo* moveTo = MoveTo::create(0.4f, targetPos); EaseOut* ease = EaseOut::create(moveTo, 3); ease->setTag(FLINGACTION_TAG); this->m_TargetNode->runAction(Repeat::create(Sequence::create(ease, callbackFunc, NULL), 1)); } else{ this->m_TargetNode->setPosition(targetPos); } } while(0); mIsProcessingScroll = false; }
// // EaseOut // EaseOut* EaseOut::create(ActionInterval *action, float rate) { EaseOut *easeOut = new (std::nothrow) EaseOut(); if (easeOut && easeOut->initWithAction(action, rate)) { easeOut->autorelease(); return easeOut; } delete easeOut; return nullptr; }
// // EaseOut // EaseOut* EaseOut::create(ActionInterval *action, float rate) { EaseOut *easeOut = new (std::nothrow) EaseOut(); if (easeOut) { if (easeOut->initWithAction(action, rate)) { easeOut->autorelease(); } else { CC_SAFE_RELEASE_NULL(easeOut); } } return easeOut; }
// // EaseOut // EaseOut* EaseOut::create(ActionInterval *pAction, float fRate) { EaseOut *pRet = new EaseOut(); if (pRet) { if (pRet->initWithAction(pAction, fRate)) { pRet->autorelease(); } else { CC_SAFE_RELEASE_NULL(pRet); } } return pRet; }
Object* EaseOut::copyWithZone(Zone *pZone) { Zone* pNewZone = NULL; EaseOut* pCopy = NULL; if(pZone && pZone->_copyObject) { //in case of being called at sub class pCopy = (EaseOut*)(pZone->_copyObject); } else { pCopy = new EaseOut(); pNewZone = new Zone(pCopy); } pCopy->initWithAction((ActionInterval*)(_inner->copy()->autorelease()), _rate); CC_SAFE_DELETE(pNewZone); return pCopy; }