所以我在我的游戏中使用libgdx的舞台类到目前为止我在舞台上添加了一个演员,它只是为屏幕绘制了一个背景,我遇到的问题是当我移动舞台的相机来模拟滚动屏幕时(背景图像大于屏幕)相机不会移动。 现在让我疯狂的是,当我在台式机启动器上运行时它会工作,但每当我在手机上运行它时它就不会滚动。 我真的不知道会出现什么问题。 我接着调用了移动摄像机的方法,因为每当调用它时,我都会将方法的名称记录到日志中,并且它会被调用。 此外,我甚至记录了相机的位置并且它发生了变化,但只有当我在桌面上运行时,如果我在手机上运行它会记录相同的位置。 我不知道这是不是一个bug因为我觉得很奇怪,它只能在桌面启动器上运行,是的,android启动器和桌面启动器都是用相同的ApplicationListener实例初始化的。 有什么建议? 提前致谢。
这是简化的代码:
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(); }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无关抱歉我希望我可以删除这个问题,但奇怪的是它在桌面上工作了。
I just realized it was indeed a problem in other of my functions which wasn't updating the camera position, so it has nothing to do with libgdx sorry I wish I could delete the question, it is strange it was working on the desktop though.
更多推荐
发布评论