Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

java - Split-Screen in 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...