Hi!
I want to make animated road using sfml, so I made objects that represent lines on the street.
There are 2 functions, init and move, while move is casted everytime, init is only used once.
These are the functions, along with function to draw them on window.
void lines::initialise(sf::RenderWindow &window){
std::vector<sf::RectangleShape> temp;
temp.resize(ammount);
siz = window.getSize().y/40;
for(int i = 0; i < ammount; i++){
temp[i].setSize(sf::Vector2f(6, siz));
temp[i].setFillColor(sf::Color(255,255,255));
}
for(int i = 0; i < ammount; i++){
temp[i].setPosition(0, siz*2*i);
}
line = temp;
}
void lines::drawintargetwindow(sf::RenderWindow &window){
int temp;
temp = window.getSize().x*0.4-3;
for(int i = 0; i < ammount; i++){
line[i].setPosition(temp, line[i].getPosition().y);
window.draw(line[i]);
}
temp = window.getSize().x*0.6-3;
for(int i = 0; i < ammount; i++){
line[i].setPosition(temp, line[i].getPosition().y);
window.draw(line[i]);
}
}
void lines::move(){
time=clock.getElapsedTime();
clock.restart();
for(int i = 0; i < ammount; i++){
line[i].move(sf::Vector2f(0, speed*time.asSeconds()));
if(line[i].getPosition().y > siz*40)
line[i].setPosition(0, 0-siz);
}
}
so the problem is, there is a gap between these lines, screen will demonstrate, second attachement shows what happens if i comment out whole content of move function (while move is still called, it is just commented out so does nothing)