5

I have problem with stretching sprites in LibGDX.

I have one png file for the sky in the game (1x1000 px) and i want to do it 1000x1000px

sprite.setSize(pixelWidth,pixelHeight);

Edit: Here is the image that I want to stretch - sky . It has little gradient from the top to the bottom as you can see. I want to make it 1000px in width. I expect image that has color-change in the width.

But I get this strange result: Image Image

You can see that there is something like gradient in width, even with lines, but with no reason, because I am scaling 1px image...

The strange thing is that everything looks fine on other PC's and mobile phones... But I don't think that the problem is in my PC!?

I don't know what to try... Any ideas?

Sorry if I didn't explained it very well.. and sorry for my bad english

Final: It was from the filtering. I changed the filter from linear to nearest and everything was fine

Yasen Bagalev
  • 51
  • 1
  • 4
  • You need to tell us what the problem is! Actually that you can see colourdifferences? If its that take a higher resolution texture. And it could be, that its just your monitor that does not show enough colours for a good result. – bemeyer Oct 03 '13 at 12:14
  • Sorry. I have edited the topic. My monitor is Acer AL511 – Yasen Bagalev Oct 03 '13 at 13:05

2 Answers2

2

i dont understand what your question realy is but a good way to scale a sprite is like this

sprite.setSize(scrw * 0.16f, scrw * 0.16f);

here scrw is your viewport's width

sandeep kundliya
  • 963
  • 8
  • 13
0

I think this is just happening because of interpolation. When your sprite and your grabbed region of the texture has a width of 1 px and you're scaling the sprite to the screen width, the GPU will interpolate some color-values and it will use colors of pixel in the neighborhood in the texture.

you could try to change your gradient to a 3px wide texture and grab your 1px wide sprite out from the middle of the 3 px. The GPU will still interpolate the colors and use pixelcolors of the neighborhood, but as they'll be the same as, it will look okay.

Here an image how your textureregion probably looks like at the moment and its grabbing area, and following the textureregion how it should look like and its grabbing area:

enter image description here

TheWhiteLlama
  • 1,276
  • 1
  • 18
  • 31