在libGDX游戏中创建夜间模式

时间:2014-05-07 23:52:28

标签: android libgdx

我正在使用libGDX框架开发Android游戏。我有一个漂亮的天空背景和一些漂亮的游戏对象在屏幕上呈现,现在我想模拟一个夜晚模式。我的问题是,是否可以在我的游戏中使用一个覆盖图,让我们说暗透明图像?我可以控制代码中的透明度以创建平滑过渡吗?

也许这不是实现这一目标的最佳方式,因此我对新想法持开放态度。

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:2)

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

编辑: 要记住的一件重要事情是记住将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();