[英]LibGDX ScalingViewport not changing position
I am trying to develop an Android app and I have stumbled across a really nasty problem. 我正在尝试开发一个Android应用,但偶然发现了一个非常讨厌的问题。
I am trying to use a different viewport from my "main" one for a different stage to control certain elements. 我试图将与“主”视口不同的视口用于不同的阶段,以控制某些元素。 I have started using Scaling viewport with Scaling.none, as it seems the most appropriate for what I am looking for.
我已经开始将Scaling视口与Scaling.none一起使用,因为它似乎最适合我要查找的内容。 The problem is, when I try to change its position, it simply does not move!
问题是,当我尝试更改其位置时,它根本不会移动! It just stays in the center of the screen.
它只是停留在屏幕的中央。 Here is the code I am using in the contructor for the viewports:
这是我在构造器中为视口使用的代码:
viewport = new StretchViewport(720, 1280, cam);
viewport.apply();
cam.position.set(cam.viewportWidth / 2, cam.viewportHeight / 2,0);
secondaryViewport = new ScalingViewport(Scaling.none, 480, 421);
secondaryViewport.setScreenPosition(240, 0);
Can't Scaling viewports be moved? 缩放视口不能移动吗?
EDIT: Here is my render() method: 编辑:这是我的render()方法:
@Override
public void render(SpriteBatch sb) {
cam.update();
secondaryViewport.getCamera().update();
sb.setProjectionMatrix(cam.combined);
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
sb.begin();
sb.setColor(Color.WHITE);
sb.draw(bg, cam.position.x - cam.viewportWidth / 2, 0, cam.viewportWidth, cam.viewportHeight);
sb.end();
stage.getViewport().apply();
stage.draw();
stage.act();
secondaryStage.getViewport().apply();
secondaryStage.draw();
secondaryStage.act();
}
By default camera position of Viewport
is at at 0,0,0
默认情况下,
Viewport
摄影机位置为0,0,0
Use this secondaryViewport.getCamera().position.set(100,100,0);
使用此
secondaryViewport.getCamera().position.set(100,100,0);
to change position of secondaryViewport. 更改secondaryViewport的位置。
secondaryViewport = new ScalingViewport(Scaling.none, 480, 421);
By this statement you're creating a new Camera
that is different from the camera which is used in your StretchViewport
. 通过此语句,您将创建一个新的
Camera
,它与StretchViewport
使用的Camera
不同。
好的,解决方法是
secondaryStage.getViewport().setScreenPosition(x, y);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.