【发布时间】:2015-07-23 21:15:06
【问题描述】:
所以我正在创建一个游戏,我将在其中绘制背景,但该背景不会覆盖整个屏幕,即使我降低窗口大小它也不会覆盖整个窗口。下面是绘制背景的代码:
Gdx.gl20.glClearColor(0.2F, 0.6F, 1F, 1F);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.update();
sb.setProjectionMatrix(cam.combined);
sb.begin();
sb.draw(Assets.splash_spr_background, 0, 0);
sb.end();
这是初始化精灵的代码:
public static Texture splash_tex_background;
public static Sprite splash_spr_background;
public static void init()
{
splash_tex_background = new Texture(Gdx.files.internal("Splash Screen/background.png"));
splash_tex_background.setFilter(TextureFilter.Linear, TextureFilter.Linear);
splash_spr_background = new Sprite(splash_tex_background);
}
最后是初始化相机和 spritebatch 的代码:
cam = new OrthographicCamera();
cam.setToOrtho(false, 1920, 1080);
sb = new SpriteBatch();
现在我的问题是:为什么这不起作用?我做错了什么?
感谢您的帮助! :)
【问题讨论】:
-
你的 background.png 的大小是多少?
-
@Funtik 它是 1280 x 720 但我认为它会缩放?
-
只有当你告诉它(bg sprite)缩放时它才会缩放。但更简洁的解决方案是使用视口来管理您的相机大小,这样您就不必像游戏中的所有其他精灵一样缩放背景。
-
我该怎么做呢?请不要只向我发送文档链接。
-
我无法比文档更好地解释它。
标签: java libgdx textures sprite scaling