按钮引擎事件声音触发器
我在 Pushbutton Engine 中使用 EventSoundTrigger 时遇到了一些问题,
我可以使用 xml 使其工作,如下所示:
<component type="com.pblabs.components.basic.EventSoundTrigger" name="Sounds">
<startSound filename="/assets/explosion.mp3" />
</component>
但是,如果我尝试编写动作脚本来执行相同的操作,则会出现错误。我在网上找不到任何示例来解释如何直接在 ActionScript 中初始化或使用 EventSoundTrigger。
以下在创建组件时抛出声音对象为空的错误。
我想出了答案:
var et:EventSoundTrigger = new EventSoundTrigger();
et.startSound = PBE.resourceManager.load("assets/noo.mp3", MP3Resource , onLoaded, onFailed) as MP3Resource ;
var tEntity:IEntity = PBE.allocateEntity();
tEntity.addComponent( et , "sound" ) ;
tEntity.initialize("tsound");
I'm running into some issues using EventSoundTrigger in Pushbutton Engine
I am able to make it work using xml like this:
<component type="com.pblabs.components.basic.EventSoundTrigger" name="Sounds">
<startSound filename="/assets/explosion.mp3" />
</component>
But if I try to write actionscript to do the same I throughs errors. I can't find any examples online to explain how to initialize or use EventSoundTrigger directly in ActionScript.
The following throws an error that the sound object is null when the component is created.
I figured it out here's the answer:
var et:EventSoundTrigger = new EventSoundTrigger();
et.startSound = PBE.resourceManager.load("assets/noo.mp3", MP3Resource , onLoaded, onFailed) as MP3Resource ;
var tEntity:IEntity = PBE.allocateEntity();
tEntity.addComponent( et , "sound" ) ;
tEntity.initialize("tsound");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来,当EventSoundTrigger组件添加到实体中时,需要startSound资源准备好。为此,您可以先加载资源,然后创建组件:
It seems that when the EventSoundTrigger component is added to the entity, it needs that the startSound resource is ready. To do so, you could load the resource first and then create the component: