0
\$\begingroup\$

I was playing angry birds and I saw that the elastic used to throw the birds is a texture that expands well when you push it with your finger.

enter image description here

How can textures like this be made in java with libgdx? What are the techniques used in cases like this?

I am asking this because it is obvious that in this situation they did not used a bunch of tiles to make an animation and I have no idea how it is made.

Thanks

\$\endgroup\$
2
\$\begingroup\$

There are some different options. You could just change the size of a regular sprite:

sprite.setSize(float width, float height);

The problem is that it will be stretched, so that doesn't really help if your sprite is anything but a solid colour.

For some cases like health-bars consisting of hearts I used a tiled drawable. A tiled drawable repeats itself rather than stretching.

You could also use a ninepatch, which is a drawable that has the extendable parts defined. Basically think of an image that consists of 9 areas where you define where the image can stretch.

This is often used for stuff like UI and other things that need to be able to change size depending on content.

NinePatch patch = new NinePatch(new Texture(Gdx.files.internal("t.png")), 12, 12, 12, 12);

There are different ways to define the areas, this uses pixel size of the texture, but some versions use black pixels on the edges of the image.

\$\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.