如何在 LibGdx 中使用 TextureRegion.split

How to use TextureRegion.split in LibGdx

我是游戏开发的新手,正在尝试在 libGDX 中拆分图像,但遇到了问题。

这是我要拆分的图像:

这是我的代码:

textureZ60=new Texture(Gdx.files.internal("data/z63.png"));
TextureRegion[][] tmp = new TextureRegion(textureZ60).split(
    textureZ60.getWidth() / column,
    textureZ60.getHeight() / row);

allFramesZ0 = new TextureRegion[column*row];

int index=0;
for (int i=0; i<row; i++) {
    for (int j=column-1; j>=0; j--) {
        allFramesZ0[index++]=tmp[i][j];
    }
}
animationZ0 = new Animation(0.25f, allFramesZ0);

我的问题是,如果我将数组降序排列 returns 6 TextureRegion:

如果我让数组升序 returns 6 TextureRegion

我尝试了所有方法,但没有返回全部 6 张不同的图像。为什么它重复红色或橙色,我怎样才能得到所有 6 个不同的图像?

请帮我解决这个问题。谢谢。

我检查并调试了它,它使用正确的数据创建了 6 个不同的 TextureRegion。似乎您的问题与动画有某种关系-也许您使用的帧速率有些错误或其他原因。 你是如何播放你的动画的?它是重复还是只重复一次? 根据您的描述,它似乎向前跳了 3 帧,最后停在最后一帧。请注意,从橙色到黑色和从红色到绿色,它们之间有 3 个帧。 如果你只播放一次,也许你应该尝试反复播放以首先验证所有加载的帧是否需要(但它可能以错误的顺序播放:red->green->purpole->red-> ...)。此外,如果您再添加一帧,它不会自行重复,而且您可能会看到所有颜色。