首页 \ 问答 \ LibGdx ImageButton播放声音(LibGdx ImageButton playing sound)

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
更新时间:2021-09-10 08:09

最满意答案

您无需添加到您的仓库:

  • 任何可以轻易再生的东西
  • 具有特定于用户的本地路径的任何内容

关于构建,理想情况下,您应该至少编写一个能够生成正确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 ...
  • 我没有尝试过这个..但我认为这将是一个普通的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.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)