libGDX-如何剪辑 [英] libGDX - How to clip

查看:108
本文介绍了libGDX-如何剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的游戏中有一个SpriteBatch,我在其batch.begin()batch.end()之间画画...

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

  1. 大型静态背景图片

  1. a large static background image

几个游戏精灵

我想裁剪显示精灵的区域,我已经阅读了使用ScissorStack完成的区域.

I want to clip the area in which the sprites are seen, which I've read is done using ScissorStack.

问题是ScissorStack似乎会裁剪发送到GPU的整个 SpriteBatch.结果是它剪切了我的游戏精灵背景图像.

The problem is that ScissorStack appears to clip the entire SpriteBatch that's sent to the GPU. The result is that it clips my game sprites and the background image.

问题:

我必须有两个单独的batch.begin()batch.end()循环,一个不带背景剪辑,另一个不带精灵剪辑吗?还是有一种无需使用ScissorStack即可仅裁剪精灵的方法?

Must I have two separate batch.begin() and batch.end() cycles, one without clipping for the background, and another with clipping for the sprites? Or is there a way of clipping just the sprites without using ScissorStack?

如果是前者,那么仅仅为了剪辑几个Sprite而将SpriteBatch刷新两次就不是很昂贵吗?或者就性能而言,真的不需要担心吗?

If the former, then isn't it rather expensive flushing the SpriteBatch twice as many times simply in order to clip a few sprites, or is it really nothing to worry about in terms of performance?

相关问题:

最新源代码中的calculateScissors()方法具有比我在任何地方记录的参数都要多的参数...

The calculateScissors() method in the latest source code has more parameters than I've seen documented anywhere...

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

viewportX, viewportY, viewportWidth, viewportHeight似乎在复制camera的视口和区域信息并且在任何文档中都未提及时,它们的目的是什么?

What is the purpose of the viewportX, viewportY, viewportWidth, viewportHeight when they appear to be duplicating the camera's viewport and area information, and are not mentioned in any docs?

基本上,我真的很困惑……即使在(或尤其是在!)测试了每个参数的不同值的行为之后.

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

寻求任何建议.

推荐答案

我没有使用ScissorStack,而是使用glScissor获得所需的结果.

Instead of using a ScissorStack I resorted to using 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();
}

希望这会有所帮助.

这篇关于libGDX-如何剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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