【问题标题】:One texture render many times一个纹理多次渲染
【发布时间】:2015-01-07 06:08:30
【问题描述】:

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

【问题讨论】:

  • 欢迎来到 Stackoverflow。请尽可能清楚地描述您的问题。问题越好,答案就越好。在发布问题之前,还要确保为您的问题搜索解决方案。在你的情况下,我建议开始阅读 wiki (github.com/libgdx/libgdx/wiki),以获得对 libgdx 的一些基本了解。该 wiki 还将向您展示如何使用 SpriteBatch 进行绘图,因此它应该可以帮助您解决问题。
  • 除了正确的问题陈述之外,您还应该提供代码,您迄今为止为自己解决问题所做的尝试。

标签: java opengl-es libgdx shader


【解决方案1】:

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

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 较大,则图像将彼此相邻。

【讨论】:

    猜你喜欢
    • 2012-09-25
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多