我开始学习libgdx和scene2d,但我的libgdx一直有问题。我的淡入淡出操作可以完美地工作,但是图像没有被缩放(即使我在构造函数中添加了缩放)……
我有一个从png 512x512加载的纹理splashTexture,它的真实图像是512x256,所以我创建了一个TextureRegion。所有这些都是在我的show方法中完成的:
@Override
public void show() {
super.show(); //sets inputprocessor to stage
splashTexture = new Texture(SPLASHADR);
// set the linear texture filter to improve the stretching
splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
splashTextureRegion = new TextureRegion(splashTexture, 0, 0, 512, 256);
}然后在我的resize方法中出现以下内容:
@Override
public void resize(int width, int height) {
stage.clear();
Drawable splashTextureDrawable = new TextureRegionDrawable(
splashTextureRegion);
Image splashImg = new Image(splashTextureDrawable);
splashImg.getColor().a = 0f;
splashImg.addAction(Actions.sequence(Actions.fadeIn(0.5f),
Actions.delay(2f), Actions.fadeOut(0.5f)));
stage.addActor(splashImg);
}这些是扩展AbstractScreen类(实际上具有render函数)的SplashScreen类中的函数:
@Override
public void render(float delta) {
stage.act(delta);
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
}任何想法都是受欢迎的,我已经研究了javadoc很久了,还没有找到解决方案!
谢谢,
bnunamak
发布于 2013-05-31 00:34:54
查看stage.setViewport(float width, float height, boolean keepAspectRatio)。这听起来像是您希望图像充满屏幕,因此将舞台的视区宽度/高度设置为图像的宽度/高度:
stage.setViewport(512, 256, false);有关keepAspectRatio参数的说明,请参阅scene2d wiki article:
setViewport有一个名为keepAspectRatio的参数,该参数仅在舞台大小和视口大小纵横比不同时才有效。如果为false,则会拉伸舞台以填充视口,这可能会扭曲纵横比。如果为true,则首先缩放舞台以适应最长维度的视口。接下来,较短的尺寸被加长以填充视口,这样可以防止纵横比发生变化。
如果这不是你想要的,这篇文章有几个不同的例子,可以满足你的需要。
https://stackoverflow.com/questions/16840895
复制相似问题