从舞台上移除演员? [英] Remove Actors from Stage?

查看:212
本文介绍了从舞台上移除演员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LibGDX并在游戏中只移动相机。昨天我创造了一种在游戏中占据一席之地的方法。我正在尝试克隆Flappy Bird,但我在绘制正在屏幕上移动的地面时遇到了问题。在每次渲染调用中,我都会在 Stage 中添加一个新的 Actor ,但是几次之后绘图就不再流动了。每秒帧数下降得非常快。还有另一种方法可以在游戏中占据一席之地吗?

I use LibGDX and move only the camera in my game. Yesterday I founded a way to draw the ground in my game. I'm trying to make a clone of Flappy Bird, but I have problems with drawing the ground which is moving on the screen. In every render call I add a new Actor to the Stage, but after a few times the drawing is no more flowing. The frames per second sink very fast. Is there another way to draw ground in games?

推荐答案

如果我读得正确,你的问题就是曾经是演员离开屏幕,它们仍然处理并导致延迟,并且您希望它们被删除。如果是这种情况,您可以简单地遍历舞台中的所有演员,将他们的坐标投影到窗口坐标,并使用它们来确定演员是否在屏幕外。

If I'm reading correctly, you're problem is that once actors go off the screen, they are still being processed and causing lag, and you want them to be removed. If that's the case, you can simply loop through all of the actors in the stage, project their coordinates to window coordinates, and use those to determine if the actor is off screen.

for(Actor actor : stage.getActors())
{
    Vector3 windowCoordinates = new Vector3(actor.getX(), actor.getY(), 0);
    camera.project(windowCoordinates);
    if(windowCoordinates.x + actor.getWidth() < 0)
        actor.remove();
}

如果窗口中的actor x坐标加上它的宽度小于0,演员完全滚动屏幕,可以删除。

If the actors x coordinate in the window plus it's width is less than 0, the actor has completely scrolled off the screen, and can be removed.

这篇关于从舞台上移除演员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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