使一个组织隐藏在其界限之外的演员 [英] Making a Group hide Actors outside of its bounds

查看:174
本文介绍了使一个组织隐藏在其界限之外的演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的图,通过在屏幕右侧添加新图像,然后使其向左移动,动态更新。这样,屏幕范围内的情节看起来就像随着时间的推移一样绘制。

I have created a very simple plot that is dynamically updated by adding new images on the right side of the screen, and then making them move towards the left side. This way, the plot within the screen's bounds looks like they are plotted as time goes by.

不幸的是,当这样做时,我必须让图像从外面开始的屏幕,并进入视图,我不能再次删除它们之前,他们完全在屏幕左侧之外。这导致图像在屏幕边界之外部分可见。

Unfortunately, when doing it this way, I have to let the images start outside of the screen, and move into view, and I can't remove them again before they are completely outside of the screen on the left side. This results in the images being partially visible outside of the screen's bounds.

控件创建为包含两个静态图像(黑色背景和屏幕的图像作为前景),以及其间的所有运动图像。然后将添加到我的舞台(像所有其他演员),并作为 Stage

The control is created as a Group that contains two static images (a black background and the image of the screen as foreground), plus all the moving images in between. This Group is then added to my Stage (like all other actors), and drawn as part of the Stage.

在下面的图片中,控件的边界标有红色。我想隐藏在这些界限之外的运动图像的部分。是否可以使用我错过的一些libGDX功能?以某种方式约束集团的绘图区域,也许?

In the image below, the control's bounds are marked with red. I would like to hide the parts of the moving images that are outside of these bounds. Is this possible to do using some libGDX functionality I have missed? By somehow constraining the Group's drawing area, perhaps?

我的其他替代方法是在屏幕前面绘制蓝色背景的部分,隐藏异常值,或者使屏幕的边缘足够厚以隐藏它们。我认为这两个解决方案是不必要的不​​方便,我确定有更好的方法来实现。

My other alternatives are to draw parts of the blue background in front of the screen, to hide the outliers, or to make the screen's edges thick enough to hide them. I think that both these solutions are unnecessarily inconvenient, and I'm pretty sure there is a better way to do this.

任何建议?

推荐答案

解决方案是使用 ScissorStack

@Override
public void draw(SpriteBatch batch, float parentAlpha) {

    //Create a scissor recangle that covers my Actor.
    Rectangle scissors = new Rectangle();
    Rectangle clipBounds = new Rectangle(getX(),getY(),getWidth(),getHeight());
    ScissorStack.calculateScissors(camera, batch.getTransformMatrix(), clipBounds, scissors);
    batch.flush(); //Make sure nothing is clipped before we want it to.
    ScissorStack.pushScissors(scissors);

    //Draw the actor as usual
    super.draw(batch, parentAlpha);

    //Perform the actual clipping
    ScissorStack.popScissors();
}

这篇关于使一个组织隐藏在其界限之外的演员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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