質問

I'm developing a game for Android using libGDX framework. I have a nice sky background and some nice game objects rendered on the screen and now I would like to simulate a night mode. My question is, is it possible to have an overlay with a, lets say dark transparent image, to render it over my game? Could I control transparency in my code to create a smooth transition?

Maybe this is not the best way to implement this so I'm open to new ideas.

役に立ちましたか?

解決

Yes, you can make use of a dark transparent image as an overlay and control the transparency :

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

他のヒント

First thing comes to mind is that you should checkout the SpriteBatch.SetColor. With it you can control the color and transparency of the overlay image you are planning to use, and if you relate the alpha value with time you willl be able to make things appear/disappear.

EDIT: An important thing to keep in mind is remembering to set the spritebatch color back to white and opaque (or your prefered color) for things to draw as they did before:

//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();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top