Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TextureRect not updating?  (Read 1105 times)

0 Members and 1 Guest are viewing this topic.

comwizz2

  • Newbie
  • *
  • Posts: 1
    • View Profile
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
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
void Object::Draw(sf::RenderWindow* Win)
{
    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.
« Last Edit: July 03, 2013, 07:51:50 pm by comwizz2 »