at the top of the file, declare std::Vector<sf::RectangleShape> spawnedFruit; and then when you 'generate fruit' do, spawnedFruit.push_back(generateFruit()); then just before window.display(). put a for loop :
for(int i = 0; i < spawnedFruit.size(); i++){
window.draw(spawnedFruit[i]);
}
basically you have to draw things every frame if you want them to be visible while using window.clear(); You may also want to define a limit to howmany fruit are allowed, otherwise the game will just keep making them and the lag will be very real. so just for example again at the top of the file:
int maxFruit = 20;
int fruitCount = 0;
then in the while loop:
if (elapsed1 >= t1){
if(fruitCount < maxFruit){
spawnedFruit.push_back(generateFruit());
fruitCount++;
}
clock.restart();
}
there's a possibilty with this that you'll need to use smart pointers or something, but try it and see first. I know vectors can be annoying.