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 中的分屏
基础教程推荐
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01