【发布时间】:2016-09-27 13:38:07
【问题描述】:
您好,我正在开发游戏,我需要滚动和重复背景。以下是我的代码:
主游戏类:
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
BitmapFont font;
float bgX =0f;
Texture background,background2;
创建时:
public void create () {
batch = new SpriteBatch();
background = new Texture("background.png");
background2 = new Texture("background.png");
渲染时:
public void render () {
batch.begin();
bgX -=1;
batch.draw(background,bgX,0,background.getWidth(),Gdx.graphics.getHeight());
batch.draw(background2,background.getWidth() + bgX,0,background.getWidth(),Gdx.graphics.getHeight());
if(bgX <- background.getWidth())
{
bgX = 0;
}
处理时:
public void dispose () {
batch.dispose();
background.dispose();
但是我得到了我想要的结果,但是几分钟后,滚动变得非常慢。
还有其他更好的选择吗?
我需要,背景从右到左重复滚动,背景高度等于Gdx.graphics.getHeight()
谢谢!提前:)
【问题讨论】:
-
Background.wrap 或类似的东西需要设置。
-
这是一个我问过并回答过的关于如何在 LibGDX 中实现滚动视差背景的问题。 stackoverflow.com/q/24587722/627005
标签: android libgdx game-engine