like in the rpg where if a character goes up the second and third will follow?
my code only does it where the second sprite follows but it lags behind after some distance
and is obviously not the solution...
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Texture heroTexture;
sf::Sprite heroSprite;
if (!heroTexture.loadFromFile("Eagle.png"))
{
std::cout << "Failed to load Eagle" << std::endl;
}
heroSprite.setTexture(heroTexture);
//square snake
std::vector<sf::Sprite>hero;
hero.push_back(sf::Sprite(heroSprite));
hero.push_back(sf::Sprite(heroSprite));
hero.push_back(sf::Sprite(heroSprite));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
hero[0].move(-10,0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
hero[0].move(+10, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
hero[0].move(0, -10);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
hero[0].move(0, +10);
}
/////////////
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
hero[1].move(-9, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
hero[1].move(+9, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
hero[1].move(0, -9);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
hero[1].move(0, +9);
}
}
window.clear();
window.draw(hero[0]);
window.draw(hero[1]);
window.draw(hero[2]);
window.display();
}
return 0;
}