libgdx - 如何添加背景图片的阶段? [英] libgdx - how to add background image in stage?

查看:571
本文介绍了libgdx - 如何添加背景图片的阶段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习libgdx但我被困在一个点..

I am learning libgdx but i am stuck at a point..

我在我的舞台增加了一个按钮,现在我想在舞台上添加一个图像,使图像看起来为背景图像的button.i意思是说,按钮应位于图像。
我一直在找教程,但没能做到这一点。

I have added a button in my stage , now i want to add a image in the stage so that the image looks as the background image to the button.i mean to say that the button should lie on the image. I have been looking tutorials but not been able to do that.

如何能不能做到?任何帮助吗?

How can it be done? any help?

推荐答案

您需要做的唯一一件事情就是的背景下,绘制<$ C $前C>按钮秒。结果
有几种可能的方式来做到这一点:结果
- 您可以添加背景为图片(子类演员)的舞台,并使用的z-index ,以确保它绘制作为背景。结果
- 你可以得到舞台取值 SpriteBatch stage.getBatch()),并利用其方法之一绘制背景,调用之前 stage.draw()

The only thing you need to do is to draw the background, before drawing the Buttons.
There are a few possible ways to do that:
- You can add the background as an Image (subclass of Actor) to the Stage and use the z-index to make sure it is drawn as a background.
- You can get the Stages SpriteBatch (stage.getBatch()) and use one of its draw methods to draw the background, before calling stage.draw()

您也可以使用另一个 SpriteBatch ,但我不推荐它,因为它是一个pretty重的对象,它是不neccessaty在这种情况下,结果
我想,之前调用 stage.draw()您需要调用 spritebatch.end(),对于 SpriteBatch 你用的背景。

You could also use another SpriteBatch, but i don't recommend it, as it is a pretty "heavy" object and it is just not neccessaty in this case.
I guess, before calling stage.draw() you need to call spritebatch.end(), for the SpriteBatch you used to draw the background.

这篇关于libgdx - 如何添加背景图片的阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆