Sorry for the delay, here's a proper MCVE that's exhibiting the same issue.
#include <SFML/Graphics.hpp>
#include <cstdlib>
#define WIN_WIDTH 640
#define WIN_HEIGHT 480
#define NUM_SHAPES 5
#define MOVE_SPEED 0.05f
#define TRANS_SPEED 0.05f
#define TRANS_DELAY 2000
sf::RenderWindow window( sf::VideoMode( WIN_WIDTH, WIN_HEIGHT ), "SFML Capture MCVE" );
sf::RectangleShape shapes[NUM_SHAPES];
sf::RectangleShape player;
bool transition = false;
bool captured = false;
sf::Int8 lastMove = 0;
sf::Texture txTrans;
sf::Sprite sprTrans;
sf::Clock clkTrans;
void ScreenTransition( const sf::Int8 lastMove ) // 0 = N, 1 = E, 2 = S, 3 = W
{
if ( !captured )
{
// Capture the screen
txTrans.create( window.getSize().x, window.getSize().y );
txTrans.update( window );
sprTrans.setTexture( txTrans, true );
captured = true;
clkTrans.restart();
}
else
{
sf::Vector2f move;
switch ( lastMove )
{
case 0:
move = sf::Vector2f( 0, -TRANS_SPEED );
break;
case 1:
move = sf::Vector2f( TRANS_SPEED, 0 );
break;
case 2:
move = sf::Vector2f( 0, TRANS_SPEED );
break;
case 3:
move = sf::Vector2f( -TRANS_SPEED, 0 );
break;
}
sprTrans.move( move );
// Fake resetting state
if ( clkTrans.getElapsedTime().asMilliseconds() > TRANS_DELAY )
{
transition = false;
captured = false;
player.setPosition( 10, 10 );
sprTrans.setPosition( 0, 0 );
}
}
}
int main()
{
for ( int i = 0; i < NUM_SHAPES; i++ )
{
shapes[i].setFillColor( sf::Color::Blue );
shapes[i].setPosition( rand() % WIN_WIDTH, rand() % WIN_HEIGHT );
shapes[i].setSize( sf::Vector2f( rand() % 1 + 100, rand() % 1 + 100 ) );
}
player.setSize( sf::Vector2f( 50, 50 ) );
player.setPosition( sf::Vector2f( 10, 10 ) );
player.setFillColor( sf::Color::Red );
sprTrans.setPosition( sf::Vector2f( 0, 0 ) );
while ( window.isOpen() )
{
sf::Event event;
while ( window.pollEvent( event ) )
{
if ( event.type == sf::Event::Closed )
window.close();
}
if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::D ) )
player.move( MOVE_SPEED, 0 );
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::A ) )
player.move( -MOVE_SPEED, 0 );
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::W ) )
player.move( 0, -MOVE_SPEED );
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::S ) )
player.move( 0, MOVE_SPEED );
if ( player.getPosition().x < 0 )
{
transition = true;
lastMove = 3;
}
else if ( player.getPosition().x + 50 > WIN_WIDTH )
{
transition = true;
lastMove = 1;
}
else if ( player.getPosition().y < 0 )
{
transition = true;
lastMove = 0;
}
else if ( player.getPosition().y + 50 > WIN_HEIGHT )
{
transition = true;
lastMove = 2;
}
if ( transition )
{
ScreenTransition( lastMove );
}
window.clear();
if ( transition && captured )
{
window.draw( sprTrans );
}
else
{
for ( int i = 0; i < NUM_SHAPES; i++ )
{
window.draw( shapes[i] );
}
window.draw( player );
}
window.display();
}
return 0;
}