LibGdx ImageButton播放声音(LibGdx ImageButton playing sound)
我用三个可绘制的图像创建了一个imageButton; 一个是按钮,一个按钮和一个按钮,其目的是为了开启和关闭游戏声音。一旦声音关闭,应该显示选中的图像。
我写过这样的代码:
soundButton = new ImageButton(new TextureRegionDrawable(soundTexture1), new TextureRegionDrawable(soundTexture2), new TextureRegionDrawable(soundTexture3)); stage.addActor(soundButton); soundButton.setPosition(Constants.WORLD_WIDTH / 4 + 300f, Constants.WORLD_HEIGHT / 4, Align.bottomLeft); soundButton.addListener(new ChangeListener(){ @Override public void changed(ChangeEvent event, Actor actor) { if(!game.soundBool) game.soundBool=true; else game.soundBool=false; } });
这里的soundBool最初是假的,游戏声音在假时会播放。 一旦我确实如此,声音就不应该发挥。这个布尔运行良好。
问题是,一旦我检查了按钮(声音关闭),声音就会永久关闭。按钮点击未按预期工作。
我如何更改代码以便更好地工作?
I have created an imageButton with three drawable images; one is button-up,button-down and button checked.Its purpose is to ON and OFF sound for the game.once sound is OFF,checked image should be displayed.
I have written the code like this:
soundButton = new ImageButton(new TextureRegionDrawable(soundTexture1), new TextureRegionDrawable(soundTexture2), new TextureRegionDrawable(soundTexture3)); stage.addActor(soundButton); soundButton.setPosition(Constants.WORLD_WIDTH / 4 + 300f, Constants.WORLD_HEIGHT / 4, Align.bottomLeft); soundButton.addListener(new ChangeListener(){ @Override public void changed(ChangeEvent event, Actor actor) { if(!game.soundBool) game.soundBool=true; else game.soundBool=false; } });
Here soundBool is initially false and game sounds will play when it is false. once I make it true,sounds should not play.This boolean is working well.
Problem is that once I checked the button(sound OFF) sound is getting OFF permanantly.Again Button click is not working as expected.
How do I change the code to work it well?
原文:https://stackoverflow.com/questions/41296228
最满意答案
您无需添加到您的仓库:
- 任何可以轻易再生的东西
- 具有特定于用户的本地路径的任何内容
关于构建,理想情况下,您应该至少编写一个能够生成正确pom的脚本,以便新贡献者能够在克隆之后尽快开始。
如果您的配置文件只包含相对路径(而不是绝对路径), 那么您可以包含这些路径,供其他人使用。
例如,请参阅“.classpath
和.project
- 检查版本控制与否? ”。You don't have to add to your repo:
- anything that can easily be regenerated
- anything with local paths specific to a user
Regarding building, ideally you should version at least a script able to generate the right pom, in order for a new contributor to be able to get going as fast as possible after cloning it.
If you can have config files with only relative paths (instead of absolute one), then you can include those, for others to use.
See for instance ".classpath
and.project
- check into version control or not?".
相关问答
更多-
rcp怎么用?[2021-06-11]
1。入门 对于入门的RCP开发人员来讲,首先应当要对RCP有一个全局性的认识,reload_cn有一篇开源文档《RCP程序设计》,下载地址为:http://www.eclipseworld.org/bbs/read.php?tid=4457,这篇文档涵盖了RCP开发相关的许多知识点,是引导新手入门的好材料。 此外,对于RCP开发应用而言,最经典的书籍还当数《Eclipse Rich Client Platform: Designing, Coding, and Packaging Java™ Applica ... -
您无需添加到您的仓库: 任何可以轻易再生的东西 具有特定于用户的本地路径的任何内容 关于构建,理想情况下,您应该至少编写一个能够生成正确pom的脚本,以便新贡献者能够在克隆之后尽快开始。 如果您的配置文件只包含相对路径(而不是绝对路径), 那么您可以包含这些路径,供其他人使用。 例如,请参阅“ .classpath和.project - 检查版本控制与否? ”。 You don't have to add to your repo: anything that can easily be regenerat ...
-
尝试在“icons”文件夹旁创建单独的“数字”文件夹。 只放置图像文件,而不是.java文件。 不要忘记将它添加到类路径和build.properties中。 那么这样的事情应该有效: InputStream in = getClass().getResourceAsStream("figures/Sound48.png"); Image image = new Image(Display.getDefault(), in); Try creating a separate "figures" folde ...
-
RCP通信(RCP communication)[2024-01-17]
我没有尝试过这个..但我认为这将是一个普通的Java进程调用。 如果B是exe。 Runtime runTime = Runtime.getRuntime(); Process process = runTime.exec("B"); I have not tried this..But i assume it would be a normal Java process invoking. If B is an exe. Runtime runTime = Runtime.get ... -
您似乎应该转到Edit Configurations...并添加新的Maven配置。 然后在工作目录:字段中输入您的app模块的路径,对我来说它是application/在项目根目录中。 在命令行:字段中放入nbm:cluster-app nbm:run-platform 。 现在,您可以通过选择新创建的配置并按绿色的“播放”箭头来运行您的应用。 It looks like you should go to Edit Configurations... and add new Maven configura ...
-
正如您发布的教程中所解释的那样,NatTable Core依赖于以下插件: org.eclipse.swt org.eclipse.jface org.eclipse.equinox.common org.eclipse.core.commands org.apache.commons.logging 在大多数情况下,产品配置中缺少org.apache.commons.logging,需要在另一个功能中添加。 As explained in the tutorial you posted, NatTable ...
-
由于您是从RCP开始的,因此Command Framework是您的最佳选择。 操作已分离,您只需在使用现有应用程序时使用。 Since you are starting on RCP the Command Framework is the way to go. Actions are depcrecated and you should only have to use when working with existing applications.
-
根据您的描述,听起来您可以看到桌子。 保存视图状态的教科书方式是通过IMemento 。 您可以在此演示文稿中查看使用此界面的代码。 作为替代方案,您也可以使用IPreferenceStore 。 当状态具有全局范围时,通常使用首选项,当特定于视图时,使用纪念品。 From your description, it sounds like you have a view with the table. The text book way to save state for a view, is via IM ...
-
我有同样的问题。 检查这两个链接。 这些是我发现的最好的教程。 一 二 I had the same problem. Check this two links. These are the best tutorials I found. one two
-
手动或通过git remote add ...命令将git remote add ...到.git/config 。 无法直接从IDE添加遥控器 。 Add remote to the .git/config, either manually or via the git remote add ... command. It's not possible to add remotes directly from the IDE.