Split-Screen in LibGDX(LibGDX 中的分屏)
问题描述
这个问题很简短.如何在 LibGDX 中创建分屏效果.如果我创建两个相机,它会做的就是在某处绘制一个,然后绘制下一个,覆盖前一个相机.然后我想使用多个屏幕,但这看起来并不可行,因为它只支持调整大小而不支持在窗口内重新定位.我还使用 Box2DDebugRenderer 和 ShapeRenderer,因此它还需要在分屏限制处切断它们.LibGDX 站点上似乎没有任何文档.
This question is short and simple. How do I create a split screen effect in LibGDX. If I create two cameras all it will do is draw one located somewhere and then draw the next, overwriting the previous camera. I then thought to use multiple screens but that doesn't look like it will work as it only supports resizing and not relocating within the window. I'm also using Box2DDebugRenderer as well as a ShapeRenderer so it would also need to cut those off at the split-screen limit. There doesn't seem to be any documentation on the LibGDX site.
推荐答案
在#libgdx IRC上询问了一下,函数Gdx.gl.glViewport( int x, int y, int width, int height) 向我指出.所以你只需要一台相机.只需设置屏幕左侧的视口,然后执行绘图命令,然后设置屏幕右侧的视口并再次绘制.像这样:
After asking around a bit on the #libgdx IRC, the function Gdx.gl.glViewport( int x, int y, int width, int height ) was pointed out to me. So you only need one camera. Just set the viewport for the left side of the screen then perform your drawing commands, then set up the viewport for the right side of the screen and draw again. like so:
@Override
public void render( float delta )
{
/*Wipe Screen to black*/
Gdx.gl.glClearColor( Color.BLACK );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT );
/*Left Half*/
Gdx.gl.glViewport( 0,0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight() );
//Set up camera with viewport in mind
draw( delta );
/*Right Half*/
Gdx.gl.glViewport( Gdx.graphics.getWidth()/2,0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight() );
//Set up camera again with other viewport in mind
draw( delta );
}
您只需要设置相机,使其以您想要的方式定位和转换到有限的屏幕,而不是整个屏幕.您还可以使用第二个摄像头.
You just need to set up the camera so that it is being positioned and transformed to the limited screen the way you want instead of the whole screen. You could potentially also use a 2nd camera.
这篇关于LibGDX 中的分屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LibGDX 中的分屏
基础教程推荐
- 大摇大摆的枚举 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
