【问题标题】:Create night mode in libGDX game在 libGDX 游戏中创建夜间模式
【发布时间】:2014-06-25 04:12:15
【问题描述】:

我正在使用 libGDX 框架为 Android 开发游戏。我有一个漂亮的天空背景和屏幕上渲染的一些漂亮的游戏对象,现在我想模拟一个夜间模式。我的问题是,是否有可能在我的游戏中渲染一个带有黑色透明图像的叠加层?我可以控制代码中的透明度以创建平滑过渡吗?

也许这不是实现它的最佳方式,所以我对新想法持开放态度。

【问题讨论】:

  • 是二维的吗?那么是的,这是可能的,因为你可以用SpriteBatch“着色”你渲染的东西

标签: android libgdx


【解决方案1】:

是的,您可以使用深色透明图像作为叠加层并控制透明度:

spriteBatch.setColor(0.5f, 0.5f, 0.5f, 0.5f); //control transparency in the update() method
spriteBatch.draw(Assets.skyBg, x, y, width, height); 
spriteBatch.draw(Assets.transparentDarkBg, x, y, width, height); 

【讨论】:

    【解决方案2】:

    首先想到的是您应该查看SpriteBatch.SetColor。 有了它,您可以控制您计划使用的叠加图像的颜色和透明度,如果您将 alpha 值与时间联系起来,您将能够使事物出现/消失。

    编辑: 需要记住的重要一点是,请记住将 spritebatch 颜色设置回白色和不透明(或您喜欢的颜色),以便像以前一样绘制:

    //Drawing Normal Textures
    spritebatch.begin();
    spritebatch.draw(myNormalTexture, x, y, w, h);
    spritebatch.end();
    //Drawing Transparent Textures
    spritebatch.setColor(1, 1, 1, transparencyLevel);
    spritebatch.begin();
    spritebatch.draw(myTransparentTexture, x, y, w, h);
    spritebatch.end();
    //Back to Drawing Normal Textures
    spritebatch.setColor(1, 1, 1, 1);
    spritebatch.begin();
    spritebatch.draw(myOtherNormalTexture, x, y, w, h);
    spritebatch.end();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多