正确方法Libgdx配置屏幕 [英] Proper way to dispose screens in Libgdx

查看:270
本文介绍了正确方法Libgdx配置屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是完全配置在Libgdx屏幕的正确方法是什么?目前,如果我点击,其中一个按钮是我的previous屏幕上的按钮仍然没有什么会做的,如果我是那个屏幕上。我应该是 .dispose() -ing一切,我可以在配置()的方法?或者是有一个简单的方法来处理一切都在屏幕上的?

What is the proper way of completely disposing of a screen in Libgdx? Currently If I click where a button was on my previous screen the button still does what it would of done if I were on that screen. Should I be .dispose()-ing everything I can in the dispose() method? or is there a simpler way to dispose of everything on screen?

推荐答案

不幸的是没有更简单的方法。这些类不共享任何一种常见的一次性界面,或类似的东西,来自动执行。有一个处理一切()方法需要手工处理时,它不再需要。

Unfortunately there is no easier way. These classes do not share any kind of common "Disposable" interface, or anything like that, to do it automatically. Everything that has a dispose() method needs to be disposed manually when it's not needed anymore.

这也适用于屏幕自己。当切换屏幕他们没有得到自动处理,但你需要做的是自己(之前调用 Game.setScreen()

This is also valid for the Screens themselves. When switching Screens they do not get disposed automatically, but you need to do that yourself (before calling Game.setScreen()).

在另一方面,这不是什么大不了的事。只要看看通过一切都在你的屏幕并检查它是否已被处理或不。如果有一个Dispose方法,调用它的配置()屏幕的

On the other hand, this is not a big deal. Just look through everything in your Screen and check whether it has to be disposed or not. If there is a dispose method, call it in dispose() of the Screen.

但是,这并不能说明你对从上次屏幕隐形按钮的行为。我想你使用舞台和使用 Gdx.input.setInputProcessor(阶段); 。此设置不会当您更改屏幕,改变你必须设置输入处理器到舞台您当前的屏幕的,或以任何处理的输入在当前屏幕。这样的老的阶段不会赶上任何输入了。

BUT this does not explain your behaviour about invisible buttons from the last Screen. I suppose you use a Stage and used Gdx.input.setInputProcessor(stage);. This setting will not be changed when you change the screen and you have to set the input processor to the Stage of your current Screen, or to whatever that handles the input in your current Screen. That way the "old" stage will not catch any inputs anymore.

这篇关于正确方法Libgdx配置屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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