Libgdx Scene2d Image from NinePatchDrawable doesn't rotate

527 Views Asked by At

I am creating an image using NinePatchDrawable and trying to rotate it using rotateBy method simply, but it is not rotating somehow. I am using following code snippet:

TextureAtlas ninePatchAtlas = game.getAssetsInterface().getTextureAtlas(Constants.GAME_ATLAS);
AtlasRegion region = ninePatchAtlas.findRegion("drawPatch");
NinePatch ninePatch = new NinePatch(region, 59, 59, 59, 59);
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(ninePatch);
Image image = new Image(ninePatchDrawable);
image.setOrigin(image.getWidth() / 2, image.getHeight() / 2);
image.setPosition(200, 400);
image.setWidth(150);
image.rotateBy(45);

rotate is working if I use another drawable instead of NinePatchDrawable on constructor of Image. Is there anyone facing the same issue?

1

There are 1 best solutions below

0
On

After investigating I have decided to use Containers as follows:

TextureAtlas ninePatchAtlas = game.getAssetsInterface().getTextureAtlas(Constants.GAME_ATLAS);
AtlasRegion region = ninePatchAtlas.findRegion("drawPatch");
NinePatch ninePatch = new NinePatch(region, 59, 59, 59, 59);
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(ninePatch);
Image image = new Image(ninePatchDrawable);
image.setWidth(150);

Container<Image> container = new Container<Image>(image);
container.fill();
container.setSize(image.getWidth(), image.getHeight());
container.setOrigin(container.getWidth() / 2, container.getHeight() / 2);
container.setTransform(true);
container.setPosition(image.getX(), image.getY());
container.rotateBy(45);

You can add container directly to stage or use its draw method in your custom widget implementation.