# How to make a tile that can be stretched out

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.

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

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.