ファイル
YMM4-LuaScript/docs/scene-ymm4.html
T

105 行
4.8 KiB
HTML

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>scene と ymm4 | Lua スクリプト for YMM4</title>
<link rel="stylesheet" href="assets/style.css">
</head>
<body>
<button id="navtoggle" aria-label="メニュー">☰</button>
<nav id="sidebar"></nav>
<main>
<h1>scene と ymm4</h1>
<p>
<code>scene</code> はシーンの解像度とシーン単位の共有値を、<code>ymm4</code> はグループ・タイムライン・再生状態などの
環境情報を提供します。
</p>
<h2>scene — シーン情報</h2>
<table>
<tr><th>メンバー</th><th>説明</th></tr>
<tr><td><code>scene.width</code></td><td>シーンの横解像度(ピクセル)</td></tr>
<tr><td><code>scene.height</code></td><td>シーンの縦解像度(ピクセル)</td></tr>
<tr><td><code>scene.cx</code></td><td>横解像度の半分(<code>scene.width / 2</code>)</td></tr>
<tr><td><code>scene.cy</code></td><td>縦解像度の半分(<code>scene.height / 2</code>)</td></tr>
<tr><td><code>scene.set(name, value)</code></td><td>シーン単位の共有領域へ値を保存します</td></tr>
<tr><td><code>scene.get(name)</code></td><td><code>scene.set()</code> で保存した値を取得します</td></tr>
</table>
<h3>シーンサイズに対する相対配置</h3>
<pre><code>obj.x = scene.cx * obj.track0 / 100</code></pre>
<h2>scene.set / scene.get — シーン内の値共有</h2>
<p>
<code>scene.set(name, value)</code> はシーン単位の共有領域へ値を保存し、
同じシーン内のすべての Lua スクリプトエフェクトから、アイテムやフレームをまたいで
<code>scene.get(name)</code> で参照できます。MoonSharp とネイティブのどちらのエンジンでも動作します。
</p>
<table>
<tr><th>引数</th><th>説明</th></tr>
<tr><td><code>name</code></td><td>値の名前(文字列)</td></tr>
<tr><td><code>value</code></td><td>保存する値(数値・文字列・真偽値)。<code>nil</code> を渡すと削除</td></tr>
</table>
<pre><code>-- アイテムA: 自分の座標を共有する
scene.set("leader_x", obj.x)
-- アイテムB: 共有された座標へ追従する
obj.x = scene.get("leader_x") or 0</code></pre>
<div class="note">
<ul>
<li>数値・文字列・真偽値以外(テーブル・関数など)は保存されません。</li>
<li>名前と文字列値は UTF-8 換算で 4095 バイトを超える部分が切り捨てられます。</li>
<li>値はシーンごとに独立しており、YMM4 を終了するまでメモリ上に保持されます(プロジェクトファイルには保存されません)。</li>
<li>アイテム間の評価順序は保証されないため、同一フレーム内での書き込みと読み取りの順序に依存する作りは避けてください。</li>
</ul>
</div>
<h2>ymm4 — 環境・メタ情報</h2>
<table>
<tr><th>メンバー</th><th>型</th><th>説明</th></tr>
<tr><td><code>ymm4.group_index</code></td><td>整数</td><td>グループ制御内の現在のインデックス(0 始まり)</td></tr>
<tr><td><code>ymm4.group_count</code></td><td>整数</td><td>グループ制御内の総アイテム数</td></tr>
<tr><td><code>ymm4.group_ratio</code></td><td>数値</td><td>グループ内の進行割合(<code>group_index / group_count</code>)</td></tr>
<tr><td><code>ymm4.timeline_totalframe</code></td><td>整数</td><td>タイムライン全体の総フレーム数</td></tr>
<tr><td><code>ymm4.timeline_totaltime</code></td><td>数値</td><td>タイムライン全体の総時間(秒)</td></tr>
<tr><td><code>ymm4.time_ratio</code></td><td>数値</td><td>現在の再生位置の割合(0.0 ~ 1.0)</td></tr>
<tr><td><code>ymm4.is_saving</code></td><td>真偽値</td><td>動画出力中のみ true</td></tr>
<tr><td><code>ymm4.is_playing</code></td><td>真偽値</td><td>再生中のみ true</td></tr>
<tr><td><code>ymm4.is_paused</code></td><td>真偽値</td><td>一時停止中のみ true</td></tr>
<tr><td><code>ymm4.scene_id</code></td><td>文字列</td><td>現在のシーンを識別する文字列(GUID)</td></tr>
</table>
<h3>グループ内のインデックスで時間差をつける</h3>
<pre><code>local d = ymm4.group_index * 0.1
local p = anim.duration(anim.delay(time, d), 0.5)
obj.alpha = p * 255</code></pre>
<h3>グループ内の進行割合で配置をずらす</h3>
<pre><code>obj.x = obj.x + ymm4.group_ratio * 400</code></pre>
<h3>出力時のみ挙動を変える</h3>
<pre><code>if ymm4.is_saving then
obj.alpha = 255
else
obj.alpha = 128
end</code></pre>
<div class="pager">
<a href="anim.html">← anim ライブラリ</a>
<a href="pixels.html">ピクセル操作 →</a>
</div>
</main>
<script src="assets/nav.js"></script>
</body>
</html>