嗨我正在开发游戏,我需要滚动和重复背景。以下是我的代码:Lbgdx:重复和滚动背景图片
主要游戏类别:
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或需要设置类似的东西。 – Madmenyo
这是一个我已经询问并回答了如何在LibGDX中实现滚动视差背景的问题。 http://stackoverflow.com/q/24587722/627005 –