With shapes it works good but not with sprites.
dinosaur::dinosaur()
{
isTextureLoaded();
isSpriteLoaded();
up = false;
down = false;
left = false;
right = false;
}
bool dinosaur::isTextureLoaded()
{
if (!texture.loadFromFile("download.png"));
return EXIT_FAILURE;
}
void dinosaur::isSpriteLoaded()
{
sprite.setTexture(texture);
}
int main()
{
dinosaur dino;
godzilla god;//
god.sprite.setScale(0.3, 0.3);
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
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)) {
god.sprite.move(-2.f, 0.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
god.sprite.move(2.f, 0.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
god.sprite.move(0.f, -2.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
god.sprite.move(0.f, +2.f);
}
//Moving Sprite 2
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
dino.sprite.move(-2.f, 0.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
dino.sprite.move(2.f, 0.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
dino.sprite.move(0.f, -2.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
dino.sprite.move(0.f, +2.f);
}
}
window.clear(sf::Color::White);
window.draw(dino.sprite);
window.draw(god.sprite);
window.display();
}
return 0;
}