オーディオ
商品説明
このコンポーネントにより、エンティティはサウンドを再生することができる。
プロパティ一覧
Property | Type | 初期値 | 商品説明 |
---|---|---|---|
url (必須) | ストリング | '' | ソースURL |
ボリューム | 番号 | 1 | 音声の再生音量 0から1の間の値 |
ループ | ブーリアン | false | 終了後にオーディオを再開するかどうか |
休止中 | ブーリアン | false | オーディオが一時停止中かどうか |
ピッチ | 番号 | 1 | オーディオのピッチを変更するために使用される係数。 1がデフォルトのピッチ。 |
ポジション | ブーリアン | false | オーディオをポジション再生するかどうか |
反射距離 | 番号 | 1 | **リスナーが遠ざかるにつれて、この音源からの音量が減少し始める距離を示す値。 負でない値でなければならない。 |
距離モデル | ストリング | '逆' | **このオーディオソースとリスナーとの間の距離が大きくなるにつれて音量を下げるために使用されるアルゴリズム。 取り得る値には、「linear」、「inverse」、「exponential」がある。 |
ロールオフ係数 | 番号 | 1 | **この音源とリスナーとの距離が離れるにつれて、音量が減少する速さ。 許容される値の範囲は、distanceModel に応じて以下のように変化する: linear: 0~1、inverse: 0~Infinity: 0から無限大、指数: 0から無限大 |
最大距離 | 番号 | 10000 | positionalがtrueで、distanceModelがlinearの場合のみ適用される。 このオーディオソースとリスナーとの最大距離。 この時点以降、体積は減らない。 正の値でなければならない。 |
関数一覧
Get
Returns a read-only reference.
Example
ecs.Audio.get(world, component.eid)
Set
Ensures the component exists on the entity, then assigns the (optional) data to the component.
Example
ecs.Audio.set(world, component.eid, {
url: '',
volume: 1,
loop: false,
paused: false,
pitch: 1,
positional: false,
refDistance: 1,
distanceModel: ''inverse'',
rolloffFactor: 1,
maxDistance: 10000
})
Mutate
Perform an update to the component within a callback function. Return true
to indicate no changes made.
Example
ecs.Audio.mutate(world, component.eid, (cursor) => {
cursor.volume = 0.5;
cursor.loop = true;
return false;
})
Remove
Removes the component from the entity.
Example
ecs.Audio.remove(world, component.eid)
Has
Returns true
if the component is present on the entity.
Example
ecs.Audio.has(world, component.eid)
Reset
Adds, or resets the component to its default state.
Example
ecs.Audio.reset(world, component.eid)
Advanced Functions
Cursor
Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.
Example
ecs.Audio.cursor(world, component.eid)
Acquire
Same behavior as cursor, but commit must be called after the cursor is done being used.
Example
ecs.Audio.acquire(world, component.eid)
Commit
Called after acquire. An optional third argument determines whether the cursor was mutated or not.
Example
ecs.Audio.commit(world, component.eid)
ecs.Audio.commit(world, component.eid, false)
Dirty
Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.
Example
ecs.Audio.dirty(world, component.eid)