Hi all, Hoping to get some help with an issue I get while trying to follow a tutorial series on youtube. I'm trying to create an animation using a 576x256 .png in each direction but my sprite disappears when I do input. Any help on this would be greatly appreciated.Here is the following code:
#include <SFML\Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(1000, 800), "SFML works!");
// sf::CircleShape shape(100.f);
// shape.setFillColor(sf::Color::Green);
float playerMovementSpeed = 1;
int walkingCounter = 0;
sf::Texture texturePlayer;
texturePlayer.loadFromFile("walksprite.png");
sf::Sprite spritePlayer(texturePlayer);
spritePlayer.setPosition(window.getSize().x / 2, window.getSize().y / 2);
spritePlayer.setTextureRect(sf::IntRect(0, 0, 64, 64));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
spritePlayer.move(0, -playerMovementSpeed);
spritePlayer.setTextureRect(sf::IntRect(walkingCounter*64, 0, 64, 64));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
spritePlayer.move(0, playerMovementSpeed);
spritePlayer.setTextureRect(sf::IntRect(walkingCounter*64, 64*2, 64, 64));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
spritePlayer.move(-playerMovementSpeed, 0);
spritePlayer.setTextureRect(sf::IntRect(walkingCounter*64, 64*1, 64, 64));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard:
))
{
spritePlayer.move(playerMovementSpeed, 0);
spritePlayer.setTextureRect(sf::IntRect(walkingCounter*64, 64*3, 64, 64));
}
walkingCounter++;
if (walkingCounter==
{
walkingCounter == 0;
}
// window.draw(shape);
window.draw(spritePlayer);
window.display();
}
return 0;
}