我在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");
答案 0 :(得分:0)
似乎当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;
}