1
Graphics / TextureRect not updating?
« on: July 03, 2013, 07:44:05 pm »
I don't know what I'm doing wrong but for some reason I cannot seem to get my animated sprite to change frames. :/ The initial Sprite.setTextureRect works fine, but every one I try to call in my loop seems to have no effect.
I was hoping to get a little insight from people more experienced than I.
Update Function
I've done my own debugging and the setTextureRec is getting called with valid values (0,0,20,20) and (0,20,20,20) But it only ever shows the first frame. even thought that line is getting executed.
Calling setTextureRect in the constructor DOES work though... so I'm puzzled. I'm sure its just operator error, but for the life of me I can't figure it out.
I was hoping to get a little insight from people more experienced than I.
Update Function
void AnimatedObject::Update(float Delta)
{
PassedTime += Delta;
if (PassedTime >= TimePerFrame)
{
PassedTime -= TimePerFrame;
CurrentFrame++;
if(CurrentFrame > LastFrame)
{
CurrentFrame = InitialFrame;
}
Sprite.setTextureRect( FindOffset(CurrentFrame,FrameSize,TextureSize) );
}
Location += sf::Vector2f(Delta,Delta);
}
Draw Function{
PassedTime += Delta;
if (PassedTime >= TimePerFrame)
{
PassedTime -= TimePerFrame;
CurrentFrame++;
if(CurrentFrame > LastFrame)
{
CurrentFrame = InitialFrame;
}
Sprite.setTextureRect( FindOffset(CurrentFrame,FrameSize,TextureSize) );
}
Location += sf::Vector2f(Delta,Delta);
}
void Object::Draw(sf::RenderWindow* Win)
{
Sprite.setPosition(Location);
Win->draw(Sprite);
}
{
Sprite.setPosition(Location);
Win->draw(Sprite);
}
I've done my own debugging and the setTextureRec is getting called with valid values (0,0,20,20) and (0,20,20,20) But it only ever shows the first frame. even thought that line is getting executed.
Calling setTextureRect in the constructor DOES work though... so I'm puzzled. I'm sure its just operator error, but for the life of me I can't figure it out.