5
\$\begingroup\$

I am new to LibGdx, i was doing one example for my learning and struck with this question, i had searched in google but i am not able to find the answer for this.

1) How to make part of the Texture not to be scaled.

enter image description here

as you can see in the image i am reducing the height of bottom pipes so that the top pipe scale is reduced to fit the height given but i want the top part of the pipe not to be scaled.

in this example whole pipe is one texture, for fixing this problem i thought to split the top and body to separate texture and set height for only body but i thought there should be some other solution so that only i had put this question here.

\$\endgroup\$
  • \$\begingroup\$ Split the tube into 2 parts, stretching and static size. \$\endgroup\$ – Kromster Feb 15 '14 at 10:05
  • \$\begingroup\$ Thanks for replay but is there is no other option for doing this, without splitting.? \$\endgroup\$ – sreeramu Feb 15 '14 at 10:07
  • \$\begingroup\$ No. There's no way of both stretching and not stretching an image at the same time. (Discounting quantum mechanics.) \$\endgroup\$ – Anko Feb 15 '14 at 12:54
  • \$\begingroup\$ Well, ok, you could implement morph target animation, but that would be overkill for a Flappy Bird clone. \$\endgroup\$ – Anko Feb 15 '14 at 13:20
  • \$\begingroup\$ Hi Anko thanks for your replay, I am using this for learning only, I had taken Flappy Bird because it is easy to learn with less graphics. \$\endgroup\$ – sreeramu Feb 15 '14 at 13:34
7
\$\begingroup\$

Option #1: Split tubes into 2 parts, the tube and the rim. So that you stretch the tube to be as long as you need it and the rim part is always the same size.

enter image description here

Option #2: Make the tubes to be always the same length and hide the ends behind the walls.

enter image description here

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

You can scale the texture coordinates over the region of the texture that you want to manipulate.

Typically, your textures are drawn using linear interpolation ("lerp"), so the texture is evenly distributed / linearly scaled across the target polygon, like so:

enter image description here

However, you can manipulate this to give non-linear interpolation by changing your texture coordinates. For instance,

enter image description here

With that example, 1. the top two quad rows contain the top 50% of the texture. 2. The third row (from the top) contains 40% of the texture (from 0.5 to 0.9) 3. The last row contains only the last 10% of the texture

This causes the texture to be stretched.

This is flexible in that you can dynamically manipulate the texture coordinates, preferably in fragment shader. I'd pass in a uniform indicating how far you wanted the platform to extend vertically, and figure out the texel coordinates based on that.

The other option is to manipulate the vertex coordinates of the 3rd row to extend the platform, which will have the same effect. As long as you have "stretching" in your tex coords, you'll get the effect you are looking for.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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