如何在纯 DHTML 游戏中控制声音
我正在考虑仅使用 Javascript、HTML 和 CSS 编写基于网络的游戏。似乎有很多类型的游戏可以使用这些技术来完成,除了一件事。我真的找不到控制声音的好方法,我看到它唯一有效的方法是将某种控件嵌入到页面中。他们是用 DHTML 制作细粒度声音效果的方法吗?
假设我玩台球游戏,想要听到球互相撞击的声音,有没有办法在不使用某种插件的情况下做到这一点?
I am looking into writing web based games using just Javascript, HTML, and CSS. It seems like there are large classes of games could be done using these technologies, except for one thing. I can't really find a good way of controlling sound, the only thing I see that it works is to embedding a control of some sort into the page. Is their a way to do fine grained sound effects in DHTML?
Lets say I had a pool game and wanted to have the sounds of the balls hitting each other, is there a way to do this without using some sort of plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 SoundManager 2 来实现此目的; SoundManager 2 是一个 JavaScript 库,用于通过良好的 API 控制网页上的声音。看看这个演示页面,其中有一些很好的示例,特别是< a href="http://www.schillmania.com/projects/soundmanager2/demo/animation-2b/" rel="nofollow noreferrer">嘈杂的页面 和 Smashable 圣诞彩灯。谷歌搜索 SoundManager 2 用法的其他示例。
这里有一些有趣的答案: 跨平台、跨浏览器如何从 Javascript 播放声音?。该线程的重要链接:
You can use SoundManager 2 for this; SoundManager 2 is a JavaScript library for controlling sound on webpages with a nice API. Have a look at this demo page, some nice examples there, particularly A Noisy Page and Smashable Christmas Lights. Google around for other examples of SoundManager 2 usages.
Some interesting answers here: Cross-platform, cross-browser way to play sound from Javascript?. Notable links from that thread:
您可以编写一个没有界面的 Flash 应用程序,您只需编写一次,然后您可以使用 javascript 与它通信以使其播放歌曲。它基本上就是“由 DHTML 控制的声音播放器”。
请参阅此链接:Javascript<>Flash 通信说明
You could write a flash application without interface which you'd only have to write once and then you can communicate to it with javascript to make it play songs. It'd basically be your "sound player controlled by DHTML".
See this link: Javascript<>Flash communication explained