I extended the RenderTarget-Class now by a new function:
void RenderTarget::setViewportt(const sf::FloatRect& rect)
{
sf::Vector2u oldSize = getSize();
m_view.reset(sf::FloatRect(0.f, 0.f, rect.width, rect.height));
m_view.setViewport(sf::FloatRect(rect.left / oldSize.x, rect.top / oldSize.y,
rect.width / oldSize.x, rect.height / oldSize.y));
m_cache.viewChanged = true;
}
Now i exactly have what i want, i can make offsets for my sprites with a cutting off at the edge. But my question now is, is that a good coding style? Perhaps i do something wrong to reach my goal? Or i do something wrong when i think i have to reach this goal?
My Plan is it, to create Surface-Classes for everything i want draw. For example a Field Surface-Class called SurfaceField needs to dispaly a Field and the figures on it, then i can simply write:
int main()
{
SurfaceField sf;
SurfaceChat sc;
renderWindow.setViewportt(sf::FloatRect(50, 50, 200, 200));
sf.draw(renderWindow);
renderWindow.setViewportt(sf::FloatRect(100, 100, 200, 200));
sc.draw(renderWindow);
}
So i simply can move my chat and my field without have to worry about the offsets in the different Objects.