Scaling the map / using Follow

Scaling the map / using Follow

I’m using tiled maps and the cocos class Follow, for follow the main player around the map. The problem that i have is when i want to scale the tiled map. It works. But when i scale the tiled map, Follow doesn’t work anymore. Videos:

Without scaling:

Now, scaling:



How can i fix it?

Quick fix is to just subclass Follow and fix it to cater for the scaling of the _target field, which you can see in Follow::step(float). In the video you posted, it seems to be moving the tile map while ignoring the scaling, so perhaps a fix would be:

void Follow::step(float /*dt*/)
        // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased

        Vec2 tempPos = _halfScreenSize - _followedNode->getPosition();

        _target->setPosition(clampf(tempPos.x, _leftBoundary, _rightBoundary) * _target->getScaleX(),
                                   clampf(tempPos.y, _bottomBoundary, _topBoundary)  * _target->getScaleY());
        _target->setPosition(_halfScreenSize - _followedNode->getPosition() * _target->getScale());

I’m simply guessing here, so that may or may not be the solution, but I’m certain that it shouldn’t be a tough issue to fix.

1 Like

Thanks @R101 !! That fixed my problem !!!
It’s a bug in Follow::step ? cc @zhangxm

Let’s ask @PatriceJiang or @coulsonwang to take a look at this thread. Is this a bug?

@tranthor did you create a GitHub issue yet and reference this thread?

Nope, First I would like to confirm if it’s a bug. Maybe not.