Libgdx混合两个面具?

时间:2015-02-13 10:28:31

标签: java opengl libgdx color-blending

屏幕分为两部分,我有两组纹理。

我希望裁剪每个纹理组以适合屏幕的每个部分。 如何使用混合(蒙版)实现这一点?

这是我用MSPaint描述情况的图像: description image

1 个答案:

答案 0 :(得分:2)

我不知道如何使用混合面具来做到这一点,但你可以通过剪刀测试来做到这一点。

private Rectangle leftSide;
private Rectangle rightSide;

public void resize (int width, int height) {
    //...

    leftSide = new Rectangle(0, 0, width/2, height);
    rightSide = new Rectangle(width/2, 0, width/2, height);
}

public void render() {

    //...

    spriteBatch.begin();
    //draw background

    spriteBatch.flush();
    ScissorStack.pushScissors(leftSide);
    //draw left side stuff that is cropped
    spriteBatch.flush();
    ScissorStack.popScissors();
    ScissorStack.pushScissors(rightSide);
    //draw right side stuff that is cropped
    spriteBatch.flush();
    ScissorStack.popScissors();
    //draw any other stuff that is not cropped on top of everything else
    spriteBatch.end();
}