简体   繁体   中英

libgdx why stage camera is not moving?

So I am using libgdx's stage class for my game so far I added an actor to the stage which just draws a background for the screen, the problem I'm having is that when I move the stage's camera to simulate a scroll through the screen (the background image is larger than the screen) the camera won't move. Now what is driving me crazy is that it DOES work when I run in on the desktop launcher, but whenever I run it on the phone it just won't scroll. I really don't know what could be the problem. I ensued that the method that moves the camera gets called cause I am logging the method's name to the log cat whenever it gets called and it does get called. Also, I even logged the camera's position and it changes but only if I run on the desktop, if I run on the phone it logs the same position. I don't know if this is a bug cause I think is quite strange that it only works on the desktop launcher, and yes both the android launcher and the desktop launcher are initialized with the same ApplicationListener instance. Any suggestions? Thanks in advance.

Here is the simplified code:

public void Create()
{
GameStage = new Stage(2000, 2000, true);

GameCamera = new OrthographicCamera(2000, 2000);
GameCamera.setToOrtho(true, 2000, 2000);

GameStage.setCamera(GameCamera);
GameStage.setViewport(2000, 2000, true);
}

public void MoveCamera()//it gets called when user drags across the screen
{
GameStage.getCamera().translate(x, y, 0);
GameStage.getCamera().update();
}


public void render()
   {
      //the background actor has been added at this point

      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

      GameStage.act(Gdx.graphics.getDeltaTime());
        GameStage.draw();

   }

我只是意识到这确实是我的其他功能中的一个问题,该问题并未更新相机的位置,因此它与libgdx无关,对不起,我希望我可以删除该问题,但是很奇怪,它正在桌面上运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM