Smooth Follow

桂志新
2023-12-01
void Follow::step(float dt)
{
    CC_UNUSED_PARAM(dt);


Point pos;
if (_boundarySet)
{
// whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
if (_boundaryFullyCovered) return;


Point tempPos = _halfScreenSize - _followedNode->getPosition();
pos = Vec2(clampf(tempPos.x, _leftBoundary, _rightBoundary), clampf(tempPos.y, _bottomBoundary, _topBoundary));
}
else {
// pos = ccpSub( halfScreenSize, followedNode_.position );
float s = _target->getScale();
pos = _halfScreenSize - _followedNode->getPosition();
pos.x *= s;
pos.y *= s;
}


Point moveVect;


Point oldPos = _target->getPosition();
double dist = pos.getDistance(oldPos);
if (dist > 1){
moveVect = (pos -oldPos)*0.05; //0.05 is the smooth constant.
oldPos = oldPos + moveVect;
_target->setPosition(oldPos);
}
}
 类似资料:

相关阅读

相关文章

相关问答