gpt4 book ai didi

android - 来自 NinePatchDrawable 的 Libgdx Scene2d 图像不旋转

转载 作者:行者123 更新时间:2023-11-29 20:57:22 24 4
gpt4 key购买 nike

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

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 的构造函数上使用另一个可绘制对象而不是 NinePatchDrawable,则旋转有效。有没有人面临同样的问题?

最佳答案

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

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

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

关于android - 来自 NinePatchDrawable 的 Libgdx Scene2d 图像不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27238272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com