i do have problem with my animation
when going to last fram or picture in sprite sheet the animation goes blank for a sec then starts all over again
i have read about this is cause by the rectangle is bigger than actual texture and can be fixed if i set repeated to true but my texture coordinates are 350 for width and 100 for height
and i do have another problem that the animation is too slow how can i fix it?
and how can i fix the animation not to go blank after last picture?
here is my code for animation function
Sprite Player::walk()
{
if (clock.getElapsedTime().asSeconds() > 1.f)
{
if (source1 == 350)
source1 = 50;
else
source1 += 50;
cout << source1<<"\n";
player.setTextureRect(IntRect (source1, 50 * direction, 50, 50));
clock.restart();
}
return player;
}
code for movment
void Player::move()
{
if (Keyboard::isKeyPressed(Keyboard::W))
player.move(0.f, -10.f);
if (Keyboard::isKeyPressed(Keyboard::A))
{
player.move(-10.f, 0.f);
direction = 1;
walk();
}
if (Keyboard::isKeyPressed(Keyboard::S))
player.move(0.f, 10.f);
if (Keyboard::isKeyPressed(Keyboard::D))
{
player.move(10.f, 0.f);
direction = 0;
walk();
}
}
loading files
Player::Player() :player(texture, source),source1(50)
{
//load the running animation
if (!texture.loadFromFile("running4.png"))
cout << "Error loading player image";
player.setScale(3, 3);
direction = 0;
}
class player
#pragma once
#include "Map.h"
class Player
{
public:
Texture texture;
IntRect source;
Sprite player;
Clock clock;
int direction;
int source1;
public:
Player();
~Player();
Sprite walk();
void move();
void boundary();
bool isAnyKeyPressed();
};