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);
}
}
{
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);
}
}