SFML community forums

Help => Graphics => Topic started by: ravenheart on October 06, 2008, 09:29:11 pm

Title: problem with scaling
Post by: ravenheart on October 06, 2008, 09:29:11 pm
well i hope u can answer this:

i have a class shooter;

Code: [Select]
class shooter
{
...
protected:
   
    unsigned int width;                
    unsigned int height;
    static sf::Image Image;            
    sf::Sprite Sprite;
public :
    void scale(float x, flaot y);
}


when my object is created, width and height are taken from its image:

Code: [Select]
shooter::shooter()  
{
    Sprite.SetImage(Image); // every sprite uses the same unique image
    width    = Image.GetWidth();
    height   = Image.GetHeight();
    Position = Sprite.GetPosition();
}

when it´s scaled the sprite should be scaled AND width and height should be re-calculated, what i tried like this:

Code: [Select]
void shooter::Scale(float x, float y)
{
    Sprite.Scale(x,y);
    width = width * x;
    height= height * y;
}

i tried it, but when i let my program write width and height i have a problem; it´s not always correct;

whats the mistake in my code?
Title: problem with scaling
Post by: Laurent on October 07, 2008, 07:43:43 am
It should be correct. But why don't you just call GetWidth() and GetHeight() instead of applying the scale manually ?