一个纹理渲染多次



我有一个小纹理来平铺我的游戏背景。所以我想一个一个地画纹理。我用libgdx opengl es做什么。

您可以通过以下方式将纹理设置为重复:

Texture tilingTexture;
tilingTexture = new Texture("tiling_texture.png");
tilingTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
//And draw it:
batch.draw(tilingTexture, 
xCoordWhereImageMustBeDisplayed, yCoordWhereImageMustBeDisplayed, 
xCoordOnImageItself, yCoordOnImageItself, 
widthOfImageToDisplay, heightOfImageToDisplay);

所以基本上如果你想无限滚动它,你只需要增加图像本身的坐标。

    xIncrement += 10;
    batch.begin();
    batch.draw(tilingTexture, 0, 0, xIncrement,0, Gdx.graphics.getWidh, Gdx.graphics.getHeight);
    batch.end();

如果 xIncrement 较大,则它只是环绕的图像的总宽度。当然,如果xIncrement超过图像宽度,您可以自己执行此操作以将其重置为0。但是使用这种包装方法,如果hightOfImageToDisplay更大,那么图像将彼此相邻平铺。

最新更新