For some reason in this code:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <ctime>
int main()
{
enum Direction{Down, Left, Right, Up};
sf::Vector2i cut(1, Down);
sf::Vector2i screenRes(800,600);
sf::Vector2f pos(0, 0);
sf::RenderWindow window(sf::VideoMode(screenRes.x,screenRes.y), "My ghaaaame");
sf::Time eTime;
sf::Texture pTexture;
sf::Sprite pImage;
sf::Clock clock1;
float charSpeed = 2.5;
int refresh = 75;
if(!pTexture.loadFromFile("playerimage.png"))
std::cout << eTime.asMicroseconds() << " -No player image in the folder!" << std::endl;
while(window.isOpen())
{
pImage.setTexture(pTexture);
eTime = clock1.getElapsedTime();
sf::Event event;
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
window.close();
break;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
cut.y = Right;
if(eTime.asMilliseconds()>= refresh)
{
cut.x++;
clock1.restart();
}
pos.x+= charSpeed;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
cut.y = Left;
if(eTime.asMilliseconds()>= refresh)
{
cut.x++;
clock1.restart();
}
pos.x-= charSpeed;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
cut.y = Down;
if(eTime.asMilliseconds()>= refresh)
{
cut.x++;
clock1.restart();
}
pos.y+= charSpeed;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
cut.y = Up;
if(eTime.asMilliseconds()>= refresh)
{
cut.x++;
clock1.restart();
}
pos.y-= charSpeed;
}
if(cut.x >= 3)
cut.x = 0;
pImage.setTextureRect(sf::IntRect(cut.x * 32, cut.y * 32, 32, 32));
pImage.setPosition(pos.x, pos.y);
window.clear(sf::Color::White);
window.draw(pImage);
window.display();
//window.setFramerateLimit(15);
}
}
when charSpeed = 2.5
sprite becomes deformed (attachment)
with any other number it is fine. Even with 2.4 and 2.51