来自NinePatchDrawable的Libgdx Scene2d图像不会旋转

时间:2014-12-01 22:09:34

标签: android libgdx scene2d

我正在使用NinePatchDrawable创建一个图像,并尝试使用rotateBy方法简单地旋转它,但它不是以某种方式旋转。我正在使用以下代码段:

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);
如果我在Image的构造函数上使用另一个drawable而不是NinePatchDrawable,则

rotate正在工作。有没有人面临同样的问题?

1 个答案:

答案 0 :(得分:2)

经过调查,我决定按如下方式使用容器:

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);

您可以直接将容器添加到舞台或在自定义小部件实现中使用其draw方法。