按钮引擎事件声音触发器

发布于 2024-11-06 08:47:03 字数 745 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你列表最软的妹 2024-11-13 08:47:03

看来,当EventSoundTrigger组件添加到实体中时,需要startSound资源准备好。为此,您可以先加载资源,然后创建组件:

PBE.resourceManager.load("assets/02.mp3", MP3Resource, onLoaded, onFailed) as MP3Resource;

private function onLoaded(resource:MP3Resource):void
{
    var et:EventSoundTrigger = new EventSoundTrigger();
    et.startSound = resource;
    var tEntity:IEntity = PBE.allocateEntity();
    tEntity.addComponent( et , "sound" ) ;
    tEntity.deferring=false;
}

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:

PBE.resourceManager.load("assets/02.mp3", MP3Resource, onLoaded, onFailed) as MP3Resource;

private function onLoaded(resource:MP3Resource):void
{
    var et:EventSoundTrigger = new EventSoundTrigger();
    et.startSound = resource;
    var tEntity:IEntity = PBE.allocateEntity();
    tEntity.addComponent( et , "sound" ) ;
    tEntity.deferring=false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文