[英]Android Studio Libgdx Sprite/Texture Transparency
我需要更改紋理/精靈的透明度,但我真的不知道該怎么做。 有什么幫助嗎?
我在這里看到兩種解決方案-一種是直接在Sprite中更改透明度:
Sprite sprite = new Sprite( yourTexture );
Sprite otherSprite = new Sprite( yourOtherTexture );
sprite.setAlpha(0.1f); // 0f is full transparent when 1f is full visible
...
batch.begin();
sprite.draw( batch ); //this one will be almost transparent
otherSprite.draw( batch ); //this one will be normal
batch.end();
您始終可以直接使用Sprite顏色進行操作:
sprite.setColor( sprite.getColor.r, sprite.getColor.g, sprite.getColor.b, 0.1f);
但這對我來說似乎是一種愚蠢的方式。
我推薦的第二個方法是將Sprite包裝到Scene2d Actor類中 ,例如Image 。 然后,您仍然可以直接更改aplha,但是您也可以使用Scene2d Actions機制,平穩地操縱演員的Alpha(就像Alpha逐步更改動畫一樣)。
Scene2d和Actions都可以在這里進行詳細描述,但是我鼓勵您在此處進行閱讀:
我將其添加到我的GameRenderer.java中:
private void drawTapTapChuggy() {
batcher.setColor(1, 1, 1, 0.5f);
batcher.draw(AssetLoader.tapTapChuggy, 28, 89, (83 * 0.9f), (52 * 0.9f));
batcher.setColor(1, 1, 1, 1.0f);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.