Okay, I'm getting really stuttering animations using a sprite sheet.
This is in main where I call my functions to check the keyboard events, and then display everything.
else
{
Keyboard_Control(window,Run,event,NewGame,Pause,text,Player1,clock);
Display_Main(window,Player1);
}
Here is my functions to animate and display the sprite.
void Entity::Display_Self(sf::RenderWindow& window)
{
sprite.setPosition(sf::Vector2f(X,Y));
window.draw(sprite);
std::cout<<"XR displayed is "<<std::to_string(XR)<<std::endl;
}
void Entity::Animate_Self(bool& Next)
{
if(MR==true)
{
if(Next==true)
{
XR+=64;
if(XR>256)
{
XR=64;
}
}
}
else if(Id==true)
{
XR=0;
}
sprite.setTextureRect(sf::IntRect(XR,YR,64,64));
std::cout<<"XR animated is "<<std::to_string(XR)<<std::endl;
}
The Display_Self is called in Display_Main, and the Animate_Self is called under the Keyboard_Control.
I used the couts in each to generate some data to show me what was happening, so, I'll post that too.
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR animated is 192
XR animated is 256
XR displayed is 256
XR displayed is 256
XR displayed is 256
XR displayed is 256
XR displayed is 256
XR animated is 64
XR animated is 128
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR displayed is 128
XR animated is 192
XR animated is 256
XR displayed is 256
XR displayed is 256
XR displayed is 256
XR displayed is 256
XR displayed is 256
The problem, to me, appears to be that the keyboard events are getting checked twice, without a call to display being made, followed by several calls to display with no keyboard event checks in between. The functions are supposed to be called one right after the other, and I don't know what is going on here!
Let me know if you need any more information. Thanks.