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

Author Topic: Sprite sizes stored in sprite class if image changed  (Read 1498 times)

0 Members and 1 Guest are viewing this topic.

diegonolan

  • Newbie
  • *
  • Posts: 26
    • View Profile
Sprite sizes stored in sprite class if image changed
« on: November 12, 2011, 04:36:26 am »
Hello, I am making a vector of sprites to hold all the sprites necessary for animation and I am running into trouble.  When I set the sprite to a new image it maintains the size of the previous sprite

Code: [Select]

Spr.SetImage(*Images.GetImgPtr("image_1"));
sf::Vector2<float> vect = Spr.GetSize();
cout << vect.x << " " << vect.y << endl;

Spr.SetImage(*Images.GetImgPtr("image_2"));
vect = Spr.GetSize();
cout << vect.x << " " << vect.y << endl;



This is putting out the same size even though the two images are not the same size.  Any one have any idea what is going on?

diegonolan

  • Newbie
  • *
  • Posts: 26
    • View Profile
Sprite sizes stored in sprite class if image changed
« Reply #1 on: November 12, 2011, 07:18:31 am »
Well, I decided it to do another way.  Instead of using 1 sprite, setting all its parameters and then then doing a SpritesVector.push_back(CurSprite); I decided to just resize the vector by one then set all the parameters of that sprite in the vector.  It fixes the problem because I am not dealing with the same sprite that seems to be holding memory from previous images, but still does not resolve the issues with the sprite not changing sizes when a new image is loaded.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite sizes stored in sprite class if image changed
« Reply #2 on: November 12, 2011, 10:58:51 am »
The sprite is not supposed to change its SubRect property automatically when the Image is changed. If it's not the same, you must change it yourself.
Laurent Gomila - SFML developer