// This code is working when written all in update method
Pixmap frame = new Pixmap(32, 3, Pixmap.Format.RGBA8888);
Texture texture = new Texture(frame);
You shouldn't be using
Pixmap for that (as general rule of thumb: if you think you need to use Pixmap for something then you are likely wrong). A
Pixmap is used to load, store or manipulate the image data in CPU memory: RAM. Manipulating image data in CPU memory is relatively slow and the resulting data can't be used to render on the screen with e.g.
For that you need to upload (copy) the data from CPU memory to GPU memory: VRAM. A
Texture is used to represent the image data in VRAM. So, indeed, you could do that by creating a
Texture out of it. Alternatively you could reuse an existing texture by calling the
texture.load(pixmap) method. However, uploading image data from RAM to VRAM is also relatively slow.
So, instead of manipulating the image data on CPU and then copying it to GPU, you're better of to use the GPU directly to achieve what you want. You didn't provide enough information about what you actually want to achieve, but here are a few options that could help you get started.
batch.draw(region.getTexture(), x, y, width * health, height, region.getU(), region.getV(), region.getU() + health * (region.getU2() - region.getU()), region.getV2());(here
heightare the location and size of bar in your world coordinates and
healthis the normalized health ranging from 0 to 1).
TextureRegionto the size of the bar. Let's say your health bar is fully opaque or only with an outerline, then you can use a single pixel
TextureRegionand scale it to be the size you want:
barch.draw(region, x, y, width * health, height);
Pixmapdoes, but instead does it directly using the GPU.