Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: add button click support to audio-demo sfx triggers

esenginef4bb5c8b65f2
diff --git a/examples/audio-demo/src/systems/sfx.ts b/examples/audio-demo/src/systems/sfx.ts
index 882acefca..7316002f1 100644
--- a/examples/audio-demo/src/systems/sfx.ts
+++ b/examples/audio-demo/src/systems/sfx.ts
@@ -1,6 +1,8 @@
import {
defineSystem, Query, Mut, Res, Time, Input, Audio,
+ UIEvents,
} from 'esengine';
+import type { UIEventQueue } from 'esengine';
import { SFXTrigger } from '../components';
const SFX_URLS = [
@@ -13,14 +15,15 @@ const SFX_URLS = [
let triggerIndex = 0;
export const sfxTriggerSystem = defineSystem(
- [Query(Mut(SFXTrigger)), Res(Time), Res(Input)],
- (query, time, input) => {
+ [Query(Mut(SFXTrigger)), Res(Time), Res(Input), Res(UIEvents)],
+ (query, time, input, events: UIEventQueue) => {
triggerIndex = 0;
- for (const [_entity, trigger] of query) {
+ for (const [entity, trigger] of query) {
trigger.cooldown = Math.max(0, trigger.cooldown - time.delta);
const key = `Digit${triggerIndex + 1}`;
- if (input.isKeyPressed(key) && trigger.cooldown <= 0) {
+ const clicked = events.hasEvent(entity, 'click');
+ if ((input.isKeyPressed(key) || clicked) && trigger.cooldown <= 0) {
const url = SFX_URLS[triggerIndex];
if (url) {
Audio.playSFX(url);