LibGDX - How to make a clip

I have one SpriteBatch in my game, between which batch.begin() and batch.end() I draw ...

  • large static background image

  • some sprites in the game

I want to crop the area where the sprites I read using ScissorStack are ScissorStack .

The problem is that ScissorStack appears to copy the entire SpriteBatch that was sent to the GPU. As a result, he fixed my sprites and background image.

Question:

Should I have two separate cycles batch.begin() and batch.end() , one without cropping for the background, and the other with clipping for sprites? Or is there a way to clip only sprites without using ScissorStack?

If the first, is it not too expensive when you drop SpriteBatch twice as often to fix multiple sprites, or is it really nothing to worry about in terms of performance?

Related Question:

The calculateScissors() method in the latest source code has more parameters than I have seen anywhere else ...

calculateScissors(camera, viewportX, viewportY, viewportWidth, viewportHeight, batchTransform, area, scissor)

What is the purpose of viewportX, viewportY, viewportWidth, viewportHeight when they seem to duplicate information about the viewport and camera and are not mentioned in any documents?

Basically, I'm really confused ... even after (or especially after!) Testing the behavior of different values ​​for each of these parameters.

Any advice.

+6
source share
1 answer

Instead of using ScissorStack, I resorted to using glScissor to get the results I needed.

 @Override public void render(float delta) { GameStage.INSTANCE.act(Gdx.graphics.getDeltaTime()); GameStage.INSTANCE.setViewport(GameGeometry.width, GameGeometry.height, true); GameStage.INSTANCE.getCamera().translate( -GameStage.INSTANCE.getGutterWidth(), -GameStage.INSTANCE.getGutterHeight(), 0); Gdx.gl.glScissor( (int) GameStage.INSTANCE.getGutterWidth() * 2, (int) GameStage.INSTANCE.getGutterHeight(), (int) Gdx.graphics.getWidth() - (int) (GameStage.INSTANCE.getGutterWidth() * 4), (int) Gdx.graphics.getHeight()); Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL10.GL_SCISSOR_TEST); GameStage.INSTANCE.draw(); } 

Hope this helps.

+4
source

All Articles