I'm opening a new question, because it's about a different problem, where a view is completely invisible.
I'm implementing a wrapping map consisting of two neighbouring parts. The problem: Only the first view is visible and works as intended. The second view is invisible and I don't know why. If you go to the left, there is a a black area instead of the second view. After having done many number changes/tests, it seems as the second view is limited to the area of the first view only. I´ve really tried to change everything, I`ve read many old posts and the view tutorials, but it is a "mission impossible". With one tiled maps, that were not bigger than the screen size it worked like a charm, unlike here. Many thanks for any help in advance.
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow mMainWindow(sf::VideoMode(1000,600), "Map", sf::Style::Close);
sf::View view(sf::Vector2f(500, 300), sf::Vector2f(1000, 600));
sf::View view2(sf::Vector2f(500, 300), sf::Vector2f(1000, 600));
sf::Image mapimage;
mapimage.loadFromFile("world1.jpg"); //1000*600 px
sf::Texture maptexture;
maptexture.loadFromImage(mapimage);
sf::Sprite mapsprite(maptexture);
sf::Sprite mapsprite2(maptexture);
mapsprite.setPosition(0, 0);
mapsprite2.setPosition(1000, 0);
sf::RectangleShape viewrect;
viewrect.setSize(sf::Vector2f(2000, 600));
viewrect.setPosition(0, 0);
viewrect.setFillColor(sf::Color(250,0,0,40));
sf::RectangleShape viewrect2;
viewrect2.setSize(sf::Vector2f(2000, 600));
viewrect2.setPosition(0, 0);
viewrect2.setFillColor(sf::Color(0,0,250,40));
float fview2 = 1;
view2.setViewport(sf::FloatRect(fview2, 0, 1, 1));
int mapmovementvar = 0;
while (mMainWindow.isOpen())
{
sf::Event event;
while (mMainWindow.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
mMainWindow.close();
break;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
system("cls");
view.move(-100, 0);
fview2=fview2+0.1f;
mapmovementvar--;
if(mapmovementvar<0)
{
mapmovementvar=19;
fview2=-0.9f;
view.reset(sf::FloatRect(1900, 0, 1000, 600));
view2.reset(sf::FloatRect(-1000, 0, 1000, 600));
}
view2.setViewport(sf::FloatRect(fview2, 0, 1, 1));
std::cout << "fview2 " << fview2 << std::endl;
std::cout << "mapmovementvar " << mapmovementvar << std::endl;
}
mMainWindow.clear();
mMainWindow.setView(view);
mMainWindow.draw(mapsprite);
mMainWindow.draw(mapsprite2);
mMainWindow.draw(viewrect);
mMainWindow.setView(view2);
mMainWindow.draw(mapsprite);
mMainWindow.draw(mapsprite2);
mMainWindow.draw(viewrect2);
mMainWindow.display();
}
return 0;
}