Audio isEnabled method
Stay organized with collections
Save and categorize content based on your preferences.
isEnabled(): boolean
Determines if game sound should be audible at this instant.
Requirements
- Your game must not omit sound while
isEnabled
returns false
. When
the value changes to false
you must stop playing any sound
immediately. When the value changes to true
you must immediately
resume any sound that would have been playing.
- You can either use
subscribe
to be notified when this value changes,
or you can check isEnabled
in every game loop.
- If you do use
subscribe
you must also use isEnabled
to get the
initial value.
Examples
engine.sound.setMute(!GameSnacks.audio.isEnabled);
GameSnacks.audio.subscribe((isEnabled) => engine.sound.setMute(!isEnabled));
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-03 UTC."],[[["\u003cp\u003e\u003ccode\u003eisEnabled()\u003c/code\u003e is a method that indicates whether game sound should currently be playing.\u003c/p\u003e\n"],["\u003cp\u003eGames must immediately react to changes in \u003ccode\u003eisEnabled()\u003c/code\u003e by stopping or resuming audio playback accordingly.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use either \u003ccode\u003esubscribe\u003c/code\u003e for real-time updates or check \u003ccode\u003eisEnabled()\u003c/code\u003e within the game loop to monitor sound status.\u003c/p\u003e\n"],["\u003cp\u003eInitial sound state should be determined using \u003ccode\u003eisEnabled()\u003c/code\u003e even when using subscriptions.\u003c/p\u003e\n"]]],[],null,["# Audio isEnabled method\n\n isEnabled(): boolean\n\nDetermines if game sound should be audible at this instant.\n\nRequirements\n------------\n\n- Your game **must not** omit sound while `isEnabled` returns `false`. When the value changes to `false` you **must** stop playing any sound immediately. When the value changes to `true` you **must** immediately resume any sound that would have been playing.\n - You can either use `subscribe` to be notified when this value changes, or you can check `isEnabled` in every game loop.\n - If you do use `subscribe` you **must** also use `isEnabled` to get the initial value.\n\nExamples\n--------\n\n engine.sound.setMute(!GameSnacks.audio.isEnabled);\n GameSnacks.audio.subscribe((isEnabled) =\u003e engine.sound.setMute(!isEnabled));"]]