Hello friends. I have a bit of a problem that I know must have a very simple answer, but I have been working on it for 2 days now with no avail.
I have created a "Camera" wrapper-class for sf::View. It allows me to set a "target" and then the view will "glide" to it. It also has a Zoom() method that will have it zoom in incremental steps toward a desired distance.
However, whenever a "glide" or "zoom" finishes, and the following block of code gets activated, it's resetting the zoom to the original factor, which displeases me greatly.
Any ideas?
(Note: There's some Box2d involved, so if something looks like it came out of nowhere, it probably has to do with that).
bool Camera::Update(sf::RenderWindow * rw)
{
if(!isGliding && !isFixed && !isZooming) //normal camera function
{
//get the position of the current target
if(!targetIsVec)
{
targetPos = zoToolbox::b22sfVec(_target->GetRootBody()->Getb2Body()->GetPosition());
_targetAngle = -zoToolbox::b22sfAngle(_target->GetRootBody()->Getb2Body()->GetAngle());
}
else
targetPos = _targetVec;
//Update the view based on the target's current location.
_view = rw->getView(); //i imagine the culprit must be one of these lines
_view.setCenter(targetPos);
_view.setRotation(_targetAngle);
_view.setSize(rw->getSize().x, rw->getSize().y);
}
Here's the code that actually handles zooming, which also appears in the Update() method. _zoomSteps is a number calculated elsewhere that tells the camera how many times it needs to zoom to get from where it started to where it needs to end up (basically makes a zoom happen over time instead of immediately).
if(isZooming)
{
if(_zoomSteps > 0)
{
std::cout << "zooming " << _zoomSteps << std::endl;
_view.zoom(_zoomSpeed);
_zoomSteps--;
}
else
{
std::cout << "zoom completed" << std::endl;
_currentZoom = _view.getViewport();
isZooming = false;
}
}
Any help would be greatly appreciated. Thanks so much!