LibGDX中的分屏 [英] Split-Screen in LibGDX

查看:173
本文介绍了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中的分屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆