Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm porting one of my old projects to sfml 2.0, and I had a background that I scaled using

sprite.setSize(windowWidth, windowHeight)

Now, it seems like setSize has ben removed in 2.0, and I'm wondering what the intended replacement is.

I know there is a setScale function, and that I could do something like:

auto size = sprite.getTexture()->getSize();
sprite.setScale(float(windowWidth)/size.x, float(windowHeight)/size.y);

but I think this is really ugly and clunky, is there another way to do it?

share|improve this question
    
What makes you think it would be done any differently that scale(newSize/oldSize) internally? If you have something that works use it. –  Byte56 Jun 13 '13 at 5:21
    
I'm not sure i get what you're saying. I'm not saying it would be done differently internally, I could always add my own wrapper around sprite to provide the method myself, but it kind of defeats the purpose of using such a framework. I don't get why he removed the method. I just want to know the most idiomatic way of drawing a background image that fills the entire screen, regardless of the texture resolution. –  bobbaluba Jun 13 '13 at 5:30
    
I guess they removed it as it gives an inconsistent interface. As Byte56 said, setSize probably changes the same scale factor that setScale sets. This means that calling setSize and then setScale leads to an unexpected result namely the setSize call is completly ignored. Changing the attached texture does change the size of the sprite too. Only speculation as I do not know sfml. –  Archy Jun 13 '13 at 7:53

1 Answer 1

up vote 5 down vote accepted

No, setSize() essentially has been replaced with setScale(), which will do the same things for you. The only difference here is, rather than telling the specific size to use, it will scale based on some factor (which is usually preferred, especially in pixel art 2D games).

The code example you posted would be perfectly fine to use here.

As an alternative, you could as well update your sf::View so the rendered view matches the texture's dimensions.

Or - probably the most elegant way to do it - you could just define a sf::VertexArray which will render a quad filling your window using the correct texture coordinates.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.