<?xml version="1.0" encoding="UTF-8" ?>
<rss version="0.91">
  <channel>
    <title>JavaScriptゲーム</title>
    <description>JavaScriptでゲームを作る！</description>
    <link>https://cript.game-ss.com/</link>
    <language>ja</language>
    <copyright>Copyright (C) NINJATOOLS ALL RIGHTS RESERVED.</copyright>

    <item>
      <title>ステータスウィンドウを表示する方法</title>
      <description>記事が長すぎてアップロードできなかったので、こちらに上げました。&lt;br /&gt;
ステータスウィンドウを表示する方法： &lt;br /&gt;
&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample08/blog/&quot; title=&quot;&quot; target=&quot;_self&quot;&gt;https://cf033538.cloudfree.jp/Game/sample08/blog/&lt;/a&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E3%82%B9%E3%83%86%E3%83%BC%E3%82%BF%E3%82%B9%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>場面を遷移する方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;前回の「選択肢を表示する方法」のコードでは、選択肢毎にコードを書く必要がありif文だらけのコードになっていました。&lt;br /&gt;
今回はこの問題を解消する方法を記します。&lt;br /&gt;
以下の例では、見た目では分かりませんが、画像、メッセージ、選択肢情報といったパラメータを変えただけで、全て共通のコードを実行しています。&lt;br /&gt;
そのため、どれだけ画像やメッセージ、選択肢が増えても、if文等のコードが増えることはありません。&lt;/p&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;670&quot; height=&quot;930&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample07/index.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;ファイル構成&lt;/h2&gt;
&lt;p&gt;ファイルとそれを入れるフォルダーを以下のような構成します。&lt;br /&gt;
※背景と人物の画像はBing Image Creatorで生成しています（AI生成）。&lt;/p&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample07&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/index.html&quot; target=&quot;_blank&quot;&gt;index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/messageWindow.js&quot; target=&quot;_blank&quot;&gt;messageWindow.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/data.js&quot; target=&quot;_blank&quot;&gt;data.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/com.js&quot; target=&quot;_blank&quot;&gt;com.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/layer.js&quot; target=&quot;_blank&quot;&gt;layer.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/loop.js&quot; target=&quot;_blank&quot;&gt;loop.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/commandWindow.js&quot; target=&quot;_blank&quot;&gt;commandWindow.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/scene.js&quot; target=&quot;_blank&quot;&gt;scene.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/js/sceneTransition.js&quot; target=&quot;_blank&quot;&gt;sceneTransition.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;css&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/css/sample.css&quot; target=&quot;_blank&quot;&gt;sample.css&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/img/bg02.jpg&quot; target=&quot;_blank&quot;&gt;bg02.jpg　※町の画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/img/bg03.jpg&quot; target=&quot;_blank&quot;&gt;bg03.jpg　※宿屋の画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/img/chara01.png&quot; target=&quot;_blank&quot;&gt;chara01.png　※プレイヤーの画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample07/img/chara03.png&quot; target=&quot;_blank&quot;&gt;chara03.png　※受付の画像（661x909px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;scene.js　-　場面情報クラス&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;class 選択肢情報クラス {
    constructor(ar) {
        this.id = ar[0];
        this.名称 = ar[1];
    }
}

class 画像情報クラス {
    constructor(ar) {
        this.スプライトid = ar[0];
        this.レイヤーid = ar[1];
        this.画像id = ar[2];
        this.x1 = ar[3];
        this.y1 = ar[4];
        this.x2 = ar[5];
        this.y2 = ar[6];
        this.表示メソッド = ar[7];
        this.p1 = ar[8];
        this.p2 = ar[9];
        this.p3 = ar[10];
    }
}

export class 場面情報クラス {
    constructor(ar) {
        this.id = ar[0];
        this.メッセージ = ar[1];

        this.選択肢情報リスト = [];
        ar[2].forEach(x =&amp;gt; this.選択肢情報リスト.push(new 選択肢情報クラス(x)));

        this.画像情報リスト = [];
        if (ar[3]) ar[3].forEach(x =&amp;gt; this.画像情報リスト.push(new 画像情報クラス(x)));
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 選択肢情報クラス&lt;/h3&gt;
&lt;p&gt;このクラスは「選択肢」を管理するためのものです。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コンストラクタ：&lt;/span&gt;クラスを作るときに、配列 ar を受け取ります。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;ar[0] は選択肢の「id」。&lt;/li&gt;
&lt;li&gt;ar[1] は選択肢の「名称」（例えば「はい」や「いいえ」など）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;このクラスを使うことで、選択肢のデータを簡単に扱えるようになります。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 画像情報クラス&lt;/h3&gt;
&lt;p&gt;このクラスは、プログラム内で表示する画像の情報を管理します。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コンストラクタ：&lt;/span&gt;配列 ar を受け取り、画像に関する情報を格納します。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スプライトid：&lt;/span&gt;画像の識別ID。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;レイヤーid：&lt;/span&gt;どの層（レイヤー）に画像を表示するか。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像id：&lt;/span&gt;実際の画像データの識別子。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;x1, y1：&lt;/span&gt;画像の開始位置（左上の座標）。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;x2, y2：&lt;/span&gt;画像の終了位置（右下の座標）。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;表示メソッド：&lt;/span&gt;画像をどのように表示するか（例えば拡大・縮小）。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;p1, p2, p3：&lt;/span&gt;追加のパラメータ（用途に応じて設定）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;このクラスにより、画像を座標やレイヤーに基づいて管理できます。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. 場面情報クラス&lt;/h3&gt;
&lt;p&gt;このクラスは、「場面」を管理するためのメインクラスです。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コンストラクタ：&lt;/span&gt;配列 ar を受け取り、以下の情報を設定します。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;id：&lt;/span&gt;場面の識別子。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージ：&lt;/span&gt;この場面で表示する文章。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;選択肢情報リスト：&lt;/span&gt;ar[2] に含まれる選択肢のデータを 選択肢情報クラス に変換して保存します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像情報リスト：&lt;/span&gt;ar[3] が存在する場合、画像データを 画像情報クラス に変換して保存します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;このクラスを利用すると、場面に対応するメッセージ、選択肢、画像を一括して扱えます。&lt;/p&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;sceneTransition.js　-　場面遷移クラス&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { スプライトクラス } from './sprite.js'; // クラスをインポート

export class 場面遷移 {
    static レイヤー管理 = {};
    static スプライト管理 = {};
    static 場面情報管理 = {};
    static 場面情報 = null;
    static 画像管理 = null;
    static メッセージウィンドウ = null;
    static コマンドウィンドウ = null;

    static async 開始する() {
        if (!場面遷移.場面情報) throw new Error(&quot;場面情報が初期化されていません&quot;);

        while (1) {
            await 場面遷移.画像を表示する();
            await 場面遷移.メッセージを表示する();
            const 選択肢情報 = 場面遷移.場面情報.選択肢情報リスト[0];
            if (!選択肢情報.名称) {
                // 選択肢情報に名称が無い場合は場面を遷移する
                場面遷移.場面情報 = 場面遷移.場面情報管理[選択肢情報.id];
                continue;
            }
            await 場面遷移.コマンドウィンドウを表示する();
        }
    }

    static async 画像を表示する() {
        if (場面遷移.場面情報.画像情報リスト.length == 0) return; // 画像情報が無い場合は何もしない

        let スプライト, 画像要素;
        const プロミスリスト = [];
        場面遷移.場面情報.画像情報リスト.forEach(画像情報 =&amp;gt; {
            スプライト = 場面遷移.スプライト管理[画像情報.スプライトid];
            if (!画像情報.画像id) {
                if (!スプライト) return; // 画像idが無い場合はスプライトを作成できないので何もしない
            } else {
                画像要素 = 場面遷移.画像管理.取得する(画像情報.画像id);
                if (スプライト) {
                    // 指定したスプライトに別の画像を設定したい場合は新たにスプライトを作り直す
                    if (スプライト.画像要素 != 画像要素) スプライト = 場面遷移.スプライトを作成する(画像要素, 画像情報);
                } else {
                    // 指定したスプライトが存在しない場合は新たに作成する
                    スプライト = 場面遷移.スプライトを作成する(画像要素, 画像情報);
                }
            }

            場面遷移.表示メソッドに従って画像を表示する(画像情報, スプライト, プロミスリスト);
        });

        if (プロミスリスト.length == 0) return;
        await Promise.all(プロミスリスト);
    }

    static スプライトを作成する(画像要素, 画像情報) {
        const スプライト = new スプライトクラス(
            場面遷移.レイヤー管理[画像情報.レイヤーid],
            画像要素,
            画像情報.x1,
            画像情報.y1,
            画像情報.x2,
            画像情報.y2
        );
        場面遷移.スプライト管理[画像情報.スプライトid] = スプライト;
        return スプライト;
    }

    static 表示メソッドに従って画像を表示する(画像情報, スプライト, プロミスリスト) {
        if ((画像情報.表示メソッド == &quot;フェードインする&quot;) || (画像情報.表示メソッド == &quot;フェードアウトする&quot;)) {
            プロミスリスト.push(スプライト[画像情報.表示メソッド](画像情報.p1));
        } else if (画像情報.表示メソッド == &quot;移動してフェードインする&quot;) {
            const 正位置 = { x: スプライト.x, y: スプライト.y };
            const 移動距離 = { x: 0, y: 0 };
            場面遷移.移動距離を取得する(画像情報, 移動距離, -640);
            スプライト.座標を設定する(
                画像情報.x1 + 移動距離.x,
                画像情報.y1 + 移動距離.y,
                画像情報.x2 + 移動距離.x,
                画像情報.y2 + 移動距離.y
            );
            プロミスリスト.push(スプライト[画像情報.表示メソッド](画像情報.p1, 画像情報.p2, 正位置.x, 正位置.y, 画像情報.p3));
        } else if (画像情報.表示メソッド == &quot;移動してフェードアウトする&quot;) {
            const 移動距離 = { x: 0, y: 0 };
            場面遷移.移動距離を取得する(画像情報, 移動距離, 640);
            プロミスリスト.push(スプライト[画像情報.表示メソッド](画像情報.p1, 画像情報.p2, 移動距離.x, 移動距離.y, 画像情報.p3));
        }
    }

    static 移動距離を取得する(画像情報, 移動距離, 基本移動距離) {
        if (画像情報.p1 &amp;gt; 0) 移動距離.x = 基本移動距離;
        else if (画像情報.p1 &amp;lt; 0) 移動距離.x = -基本移動距離;

        if (画像情報.p2 &amp;gt; 0) 移動距離.y = 基本移動距離;
        else if (画像情報.p2 &amp;lt; 0) 移動距離.y = -基本移動距離;
    }

    static async メッセージを表示する() {
        if (!場面遷移.場面情報.メッセージ) return; // 表示するメッセージが無い場合は何もしない
        await 場面遷移.メッセージウィンドウ.表示する();
        await 場面遷移.メッセージウィンドウ.メッセージを表示する(場面遷移.場面情報.メッセージ);
    }

    static async コマンドウィンドウを表示する() {
        const id = await 場面遷移.コマンドウィンドウ.表示する(場面遷移.場面情報.選択肢情報リスト);
        場面遷移.場面情報 = 場面遷移.場面情報管理[id];
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 場面遷移クラス全体の役割&lt;/h3&gt;
&lt;p&gt;このクラスは、プログラムの場面を管理するためのメインクラスです。例えば、特定の画像やメッセージを表示したり、場面を切り替えたりします。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;静的プロパティ：&lt;/span&gt;各種データ（レイヤー管理、スプライト管理、場面情報管理など）を一括で管理します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面遷移：&lt;/span&gt;開始する メソッドを呼び出すことで、プログラムの場面遷移が始まります。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ループ構造：&lt;/span&gt;無限ループ (while(1)) を使って、場面表示の処理を繰り返します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 静的プロパティ&lt;/h3&gt;
&lt;p&gt;場面遷移クラスでは、多くのデータを静的プロパティで管理しています。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;レイヤー管理：&lt;/span&gt;レイヤー（表示する層）を管理します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スプライト管理：&lt;/span&gt;スプライト（プログラム内の画像要素）を管理します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面情報管理：&lt;/span&gt;複数の場面に対応するデータを保存します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面情報：&lt;/span&gt;現在の場面のデータを保持します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像管理：&lt;/span&gt;画像を取得したりするための機能を提供します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウ &amp;amp; コマンドウィンドウ：&lt;/span&gt;メッセージや選択肢を表示するための管理要素です。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. 場面を開始する: 開始する メソッド&lt;/h3&gt;
&lt;p&gt;このメソッドは、場面遷移の主要な処理を行います。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;処理手順：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;初期化チェック：&lt;/span&gt;場面情報 が設定されていない場合はエラー (throw new Error) を発生させます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像とメッセージの表示：&lt;/span&gt;画像を表示する メソッドで画像を表示し、次に メッセージを表示する メソッドでメッセージを表示します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面遷移：&lt;/span&gt;選択肢情報に基づいて次の場面を設定します。選択肢に名称がない場合は、自動的に次の場面に進みます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;選択肢の表示：&lt;/span&gt;コマンドウィンドウを表示する メソッドで選択肢をユーザーに提示します。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. 画像を表示する: 画像を表示する メソッド&lt;/h3&gt;
&lt;p&gt;画面に画像を表示するための処理を行います。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像情報の確認：&lt;/span&gt;現在の場面情報に画像情報がない場合は何もしません。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スプライトの作成：&lt;/span&gt;必要に応じて新しいスプライト（画像要素）を作成します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;表示メソッド：&lt;/span&gt;画像を表示する際の方法（フェードインや移動など）に従って処理します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;非同期処理：&lt;/span&gt;Promise.all を利用して画像表示の処理が完了するのを待ちます。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;5. スプライトの管理: スプライトを作成する メソッド&lt;/h3&gt;
&lt;p&gt;スプライトは、画像を画面上に表示するための単位です。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;パラメータ：&lt;/span&gt;画像要素、座標 (x1, y1, x2, y2) を指定してスプライトを作成します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;レイヤー設定：&lt;/span&gt;スプライトを配置するレイヤーを管理します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;6. 画像表示メソッドの適用: 表示メソッドに従って画像を表示する メソッド&lt;/h3&gt;
&lt;p&gt;画像の表示方法を指定して実行します。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェードイン/フェードアウト：&lt;/span&gt;画像を徐々に表示したり消したりします。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動して表示：&lt;/span&gt;画像を指定した位置に移動させながら表示します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;座標計算：&lt;/span&gt;必要に応じて移動距離や座標を計算します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;7. メッセージ表示: メッセージを表示する メソッド&lt;/h3&gt;
&lt;p&gt;場面のメッセージを画面に表示します。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウの表示：&lt;/span&gt;メッセージウィンドウを表示します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージ内容の更新：&lt;/span&gt;現在の場面のメッセージを設定して表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;8. 選択肢の表示: コマンドウィンドウを表示する メソッド&lt;/h3&gt;
&lt;p&gt;選択肢情報リストに基づいて選択肢を表示します。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;選択肢の取得：&lt;/span&gt;ユーザーが選んだ選択肢のIDを取得します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面遷移：&lt;/span&gt;選択肢に応じて次の場面情報を設定します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;sample.js　-　サンプルクラス&lt;/h2&gt;
&lt;p&gt;このプログラムでは、次のような流れで「場面」を管理します：&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;必要な画像やレイヤー、ウィンドウを準備。&lt;/li&gt;
&lt;li&gt;「場面」の情報（テキスト、画像、選択肢など）を管理する。&lt;/li&gt;
&lt;li&gt;実際に選択肢を選びながら場面を遷移する仕組みを実現。&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { レイヤークラス } from './layer.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート
import { メッセージウィンドウクラス } from './messageWindow.js'; // クラスをインポート
import { コマンドウィンドウクラス } from './commandWindow.js'; // クラスをインポート
import { Data } from './data.js'; // クラスをインポート
import { 場面情報クラス } from './scene.js'; // クラスをインポート
import { 場面遷移 } from './sceneTransition.js'; // クラスをインポート

export class サンプル {
    static 遷移データリスト = [
        [&quot;スタート&quot;, , [[&quot;町の広場へ行く&quot;,]],]
        , [&quot;町の広場へ行く&quot;, &quot;プレイヤーは町の広場に来た&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]], [[&quot;背景01&quot;, , , , , , , &quot;フェードアウトする&quot;, 1, ,], [&quot;背景01&quot;, &quot;レイヤー1&quot;, &quot;町&quot;, 0, 0, 640, 640, &quot;フェードインする&quot;, 1, ,], [&quot;人物01&quot;, , , , , , , &quot;移動してフェードアウトする&quot;, -20, 0, 1], [&quot;人物01&quot;, &quot;レイヤー2&quot;, &quot;プレイヤー&quot;, 0, 0, 640, 640, &quot;移動してフェードインする&quot;, -20, 0, 1]]]
        , [&quot;町の広場&quot;, &quot;どうする？&quot;, [[&quot;話す&quot;, &quot;話す&quot;], [&quot;持物を見る&quot;, &quot;持物を見る&quot;], [&quot;移動する&quot;, &quot;移動する&quot;]],]
        , [&quot;話す&quot;, &quot;話が聞けそうな人は誰もいない&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]],]
        , [&quot;持物を見る&quot;, &quot;今のところ、何も持っていない&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]],]
        , [&quot;移動する&quot;, &quot;どこへ行く？&quot;, [[&quot;町の広場&quot;, &quot;やめる&quot;], [&quot;武器屋へ行く&quot;, &quot;武器屋へ行く&quot;], [&quot;防具屋へ行く&quot;, &quot;防具屋へ行く&quot;], [&quot;道具屋へ行く&quot;, &quot;道具屋へ行く&quot;], [&quot;宿屋へ行く&quot;, &quot;宿屋へ行く&quot;], [&quot;町を出る&quot;, &quot;町を出る&quot;]],]
        , [&quot;武器屋へ行く&quot;, &quot;武器屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]],]
        , [&quot;防具屋へ行く&quot;, &quot;防具屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]],]
        , [&quot;道具屋へ行く&quot;, &quot;道具屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]],]
        , [&quot;宿屋へ行く&quot;, &quot;プレイヤーは宿屋に来た&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;宿屋01&quot;,]], [[&quot;背景01&quot;, , , , , , , &quot;フェードアウトする&quot;, 1, ,], [&quot;背景01&quot;, &quot;レイヤー1&quot;, &quot;宿屋&quot;, 0, 0, 640, 640, &quot;フェードインする&quot;, 1, ,], [&quot;人物01&quot;, , , , , , , &quot;移動してフェードアウトする&quot;, 20, 0, 1]]]
        , [&quot;宿屋01&quot;, &quot;受付：&amp;lt;br&amp;gt;いらっしゃいませ&amp;lt;br&amp;gt;一泊100カーネですが&amp;lt;br&amp;gt;お泊りになりますか？&quot;, [[&quot;宿屋02&quot;, &quot;泊まる&quot;], [&quot;宿屋05&quot;, &quot;やめる&quot;]], [[&quot;人物01&quot;, &quot;レイヤー2&quot;, &quot;受付&quot;, 0, 0, 640, 640, &quot;移動してフェードインする&quot;, 20, 0, 1]]]
        , [&quot;宿屋02&quot;, &quot;受付：&amp;lt;br&amp;gt;それではお休みください&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;宿屋03&quot;,]],]
        , [&quot;宿屋03&quot;, &quot;プレイヤーはしばし眠りについた&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;宿屋04&quot;,]], [[&quot;背景01&quot;, , , , , , , &quot;フェードアウトする&quot;, 1, ,], [&quot;人物01&quot;, , , , , , , &quot;移動してフェードアウトする&quot;, -20, 0, 1], [&quot;人物01&quot;, &quot;レイヤー2&quot;, &quot;プレイヤー&quot;, 0, 0, 640, 640, &quot;移動してフェードインする&quot;, -20, 0, 1]]]
        , [&quot;宿屋04&quot;, &quot;受付：&amp;lt;br&amp;gt;お早うございます&amp;lt;br&amp;gt;またのお越しをお待ちしております&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場へ行く&quot;,]], [[&quot;背景01&quot;, , , , , , , &quot;フェードインする&quot;, 1, ,], [&quot;人物01&quot;, , , , , , , &quot;移動してフェードアウトする&quot;, 20, 0, 1], [&quot;人物01&quot;, &quot;レイヤー2&quot;, &quot;受付&quot;, 0, 0, 640, 640, &quot;移動してフェードインする&quot;, 20, 0, 1]]]
        , [&quot;宿屋05&quot;, &quot;受付：&amp;lt;br&amp;gt;やめるのですね&amp;lt;br&amp;gt;またのお越しをお待ちしております&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場へ行く&quot;,]],]
        , [&quot;町を出る&quot;, &quot;まだ装備が整っていない&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]],]];

    static async main() {
        await サンプル.使用する画像を読み込む();
        サンプル.ループ処理を作成する();
        サンプル.メッセージウィンドウを作成する();
        サンプル.コマンドウィンドウを作成する();
        サンプル.レイヤーを作成する();
        サンプル.場面情報管理を作成する();
        場面遷移.開始する();
    }

    static async 使用する画像を読み込む() {
        const 画像情報リスト = [
            { id: '町', src: 'img/bg02.jpg' },
            { id: '宿屋', src: 'img/bg03.jpg' },
            { id: 'プレイヤー', src: 'img/chara01.png' },
            { id: '受付', src: 'img/chara03.png' }
        ];
        場面遷移.画像管理 = new 画像管理クラス();
        await 場面遷移.画像管理.画像を読み込む(画像情報リスト);
    }

    static ループ処理を作成する() {
        ループ.初期化する();
        ループ.開始する();
    }

    static メッセージウィンドウを作成する() {
        場面遷移.メッセージウィンドウ = new メッセージウィンドウクラス(&quot;.スクリーン&quot;, &quot;.メッセージウィンドウ&quot;);
        Data.オブジェクト管理[&quot;サンプル&quot;] = サンプル;
    }

    static コマンドウィンドウを作成する() {
        場面遷移.コマンドウィンドウ = new コマンドウィンドウクラス(&quot;.スクリーン&quot;, &quot;.コマンドウィンドウ&quot;);
    }

    static レイヤーを作成する() {
        場面遷移.レイヤー管理[&quot;レイヤー1&quot;] = new レイヤークラス('canvas.レイヤー1'); // 背景用のレイヤ
        場面遷移.レイヤー管理.レイヤー1.描画処理をループ処理に追加する();
        場面遷移.レイヤー管理[&quot;レイヤー2&quot;] = new レイヤークラス('canvas.レイヤー2'); // 前景用のレイヤ
        場面遷移.レイヤー管理.レイヤー2.描画処理をループ処理に追加する();
    }

    static 場面情報管理を作成する() {
        サンプル.遷移データリスト.forEach(x =&amp;gt; 場面遷移.場面情報管理[x[0]] = new 場面情報クラス(x));
        場面遷移.場面情報 = 場面遷移.場面情報管理['スタート'];
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 必要なクラスのインポート&lt;/h3&gt;
&lt;p&gt;最初に、import 文で外部ファイルに定義されたクラスを読み込んでいます。各クラスの役割は以下の通りです：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像管理クラス：&lt;/span&gt;使用する画像を読み込み、管理する。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;レイヤークラス：&lt;/span&gt;背景やキャラクターなどの表示エリア（レイヤー）を作成する。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ループクラス：&lt;/span&gt;処理を繰り返すための仕組み（主にアニメーション）。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウクラス：&lt;/span&gt;メッセージを表示するウィンドウを制御。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コマンドウィンドウクラス：&lt;/span&gt;選択肢（コマンド）を表示するウィンドウ。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面情報クラス：&lt;/span&gt;各場面のデータ（テキストや画像など）を管理。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;場面遷移：&lt;/span&gt;現在の場面を変更してストーリーを進める。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. サンプルクラスの役割&lt;/h3&gt;
&lt;p&gt;サンプルクラスは、このプログラムのセットアップと管理を行います。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;重要な静的プロパティ：&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;遷移データリスト：&lt;/span&gt;各場面の情報（テキスト、画像、選択肢）を定義した配列です。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;例えば、&quot;町の広場へ行く&quot; という選択肢を選んだときのシーンが定義されています&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. サンプルクラスのメソッド&lt;/h3&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;1. main メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;プログラムの全体的な流れを準備する主なメソッドです。以下の処理を行います。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;画像の準備（使用する画像を読み込む）。&lt;/li&gt;
&lt;li&gt;レイヤーやウィンドウの作成。&lt;/li&gt;
&lt;li&gt;場面遷移.開始する を呼び出してプログラムを開始。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;2. 使用する画像を読み込む メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;必要な画像（背景やキャラクター）を読み込む処理。&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 画像情報リスト = [
    { id: '町', src: 'img/bg02.jpg' },
    { id: '宿屋', src: 'img/bg03.jpg' },
    { id: 'プレイヤー', src: 'img/chara01.png' },
    { id: '受付', src: 'img/chara03.png' }
];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;このように、画像の識別IDとファイルパスを指定して管理します&lt;/p&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;3. ループ処理を作成する メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;プログラム全体で利用する「繰り返し処理」を初期化し、開始します。&lt;/p&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;4. メッセージウィンドウを作成する メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;プレイヤーにメッセージを表示するためのウィンドウを用意します。&lt;/p&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;5. コマンドウィンドウを作成する メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;プレイヤーが選択肢を選べるウィンドウを作成します。&lt;/p&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;6. レイヤーを作成する メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;描画を行うための「レイヤー」を作成。画面の背景やキャラクターの表示を管理します。&lt;/p&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;7. 場面情報管理を作成する メソッド&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;遷移データリスト をもとに、各場面を管理するオブジェクトを作成します。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. 各場面のデータ構造（遷移データリスト）&lt;/h3&gt;
&lt;p&gt;遷移データリスト には各場面の情報が含まれています。&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;[&quot;町の広場へ行く&quot;, &quot;プレイヤーは町の広場に来た&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;, [[&quot;町の広場&quot;,]], [[&quot;背景01&quot;, &quot;レイヤー1&quot;, &quot;町&quot;, 0, 0, 640, 640, &quot;フェードインする&quot;, 1, ,]]]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;これは、「町の広場へ行く」という選択肢を選んだときに表示する情報を表します。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージ：&lt;/span&gt;プレイヤーは町の広場に来た。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;選択肢情報：&lt;/span&gt;次に選べる選択肢。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像情報：&lt;/span&gt;背景やキャラクターの画像をどのように表示するか（例えば「フェードイン」）。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;5. プログラムの開始&lt;/h3&gt;
&lt;p&gt;プログラムは addEventListener('load', サンプル.main) でスタート。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ページが読み込まれると、main が実行され、セットアップが行われます。&lt;/li&gt;
&lt;/ul&gt;
&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907708&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907708&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907708&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;&lt;/div&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E5%A0%B4%E9%9D%A2%E3%82%92%E9%81%B7%E7%A7%BB%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>選択肢を表示する方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;選択肢を表示する方法を記します。&lt;br /&gt;
以下の例では、選択肢をクリックすると該当するメッセージを表示します。&lt;/p&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;670&quot; height=&quot;930&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample06/index.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;ファイル構成&lt;/h2&gt;
&lt;p&gt;ファイルとフォルダーを以下のような構成します。&lt;br /&gt;
※前回と同じファイル名でも内容が変わっている場合があります。&lt;br /&gt;
※背景と人物の画像はBing Image Creatorで生成しています（AI生成）。&lt;/p&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample05&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/index.html&quot; target=&quot;_blank&quot;&gt;index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/messageWindow.js&quot; target=&quot;_blank&quot;&gt;messageWindow.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/data.js&quot; target=&quot;_blank&quot;&gt;data.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/com.js&quot; target=&quot;_blank&quot;&gt;com.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/layer.js&quot; target=&quot;_blank&quot;&gt;layer.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/loop.js&quot; target=&quot;_blank&quot;&gt;loop.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/js/commandWindow.js&quot; target=&quot;_blank&quot;&gt;commandWindow.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;css&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/css/sample.css&quot; target=&quot;_blank&quot;&gt;sample.css&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/img/bg02.jpg&quot; target=&quot;_blank&quot;&gt;bg02.jpg　※背景画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample06/img/chara01.png&quot; target=&quot;_blank&quot;&gt;chara01.png　※人物画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;index.html　-　HTML&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang=&quot;ja&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=660,user-scalable=no,shrink-to-fit=yes&quot;&amp;gt;
    &amp;lt;title&amp;gt;選択肢を表示する方法&amp;lt;/title&amp;gt;
    &amp;lt;link href=&quot;css/sample.css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;script type=&quot;module&quot; src=&quot;js/sample.js&quot;&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;aside class=&quot;画面更新情報&quot;&amp;gt;
        &amp;lt;p&amp;gt;
            リフレッシュレート：&amp;lt;span class=&quot;リフレッシュレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;Hz
            ／フレームレート：&amp;lt;span class=&quot;フレームレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;fps
        &amp;lt;/p&amp;gt;
    &amp;lt;/aside&amp;gt;
    &amp;lt;main class=&quot;スクリーン&quot;&amp;gt;
        &amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
        &amp;lt;canvas class=&quot;レイヤー2&quot; width=&quot;640&quot; height=&quot;640&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
        &amp;lt;article class=&quot;メッセージウィンドウ 消去 透明化&quot;&amp;gt;
            &amp;lt;p class=&quot;メッセージエリア&quot;&amp;gt;
                &amp;lt;span class=&quot;メッセージ&quot;&amp;gt;&amp;lt;/span&amp;gt;
                &amp;lt;span class=&quot;カーソル 点滅 不可視化&quot;&amp;gt;■&amp;lt;/span&amp;gt;
            &amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
        &amp;lt;article class=&quot;コマンドウィンドウ 消去&quot;&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;0&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;1&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;2&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;3&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;4&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;5&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;6&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;7&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;8&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
            &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;9&quot;&amp;gt;
                &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt;
        &amp;lt;/article&amp;gt;
    &amp;lt;/main&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 全体の構造&lt;/h3&gt;
&lt;p&gt;このHTMLは前回の「メッセージウィンドウを表示する方法」に「コマンドウィンドウ」クラスの要素を追加しており、それ以外はほぼ同じです。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. コマンドウィンドウ&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;article class=&quot;コマンドウィンドウ 消去&quot;&amp;gt;
    &amp;lt;button class=&quot;通常ボタン&quot; value=&quot;0&quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/button&amp;gt;
    &amp;lt;!-- 以下省略 --&amp;gt;
&amp;lt;/article&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;役割：&lt;/span&gt;選択肢を表示するウィンドウ。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クラス設定：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コマンドウィンドウ：&lt;/span&gt;ウィンドウのスタイルを定義。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;消去：&lt;/span&gt;初期状態では非表示（CSSでdisplay: none）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;動的要素：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;button&amp;gt;：&lt;/span&gt;各ボタンが選択肢を表し、value 属性でボタンの番号を指定。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;span&amp;gt;：&lt;/span&gt;ボタン上に表示するテキストを動的に更新。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;sample.css　-　CSS&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;:root {
    --通常文字サイズ: 26px;
    --通常文字行高さ: 38px;
    --小文字サイズ: 18px;
    --小文字行高さ: 24px;
    --黒い影: 1px 1px 1px #000, -1px -1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, 2px 0px 1px #000, -2px -0px 1px #000, 0px 2px 1px #000, 0px -2px 1px #000;
    --トランジションスピード: 0.8s;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior-y: none;
}

.画面更新情報 {
    text-align: center;
    font-size: var(--小文字サイズ);
    line-height: var(--小文字行高さ);
    color: #333;
}

.スクリーン {
    width: 640px;
    height: 840px;
    margin: 20px auto;
    border: 2px solid #ccc;
    position: relative;
    background-color: black;
}

canvas {
    position: absolute;
    top: 200px;
}

.不可視化 {
    visibility: hidden;
}

.透明化 {
    opacity: 0;
}

.消去 {
    display: none;
}

.表示 {
    display: block;
}

@keyframes 点滅 {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.点滅 {
    animation: 点滅 1s ease-out infinite;
}

.メッセージウィンドウ {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    border: solid 3px white;
    padding: 12px 17px;
    margin: 5px;
    transition: opacity var(--トランジションスピード) ease-out;
}

    .メッセージウィンドウ .メッセージエリア {
        padding: 3px;
        margin: 0px;
        font-size: var(--通常文字サイズ);
        line-height: var(--通常文字行高さ);
        color: white;
        text-shadow: var(--黒い影);
        width: 584px;
        height: 154px;
        overflow: scroll;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

        .メッセージウィンドウ .メッセージエリア::-webkit-scrollbar {
            display: none;
        }

    .メッセージウィンドウ .カーソル {
        transition: opacity var(--トランジションスピード) ease-in;
        font-size: var(--通常文字サイズ);
        display: inline-block;
        transform: translateY(-2px);
    }

.通常ボタン {
    font-size: var(--小文字サイズ);
    line-height: var(--小文字行高さ);
    color: white;
    text-shadow: var(--黒い影);
    background-color: rgba(250, 250, 250, 0.1);
    background-image: linear-gradient(to top left, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4) 30%, rgba(255, 255, 255, 0.3));
    box-shadow: inset 2px 2px 3px rgba(255, 255, 255, 0.6), inset -2px -2px 3px rgba(0, 0, 0, 0.6);
    border: solid 1px black;
    border-radius: 5px;
    padding: 10px 20px;
    margin:1px 0;
}

    .通常ボタン:hover {
        background-color: rgb(255, 255, 45);
    }

    .通常ボタン:active {
        box-shadow: inset -2px -2px 3px rgba(255, 255, 255, 0.6), inset 2px 2px 3px rgba(0, 0, 0, 0.6);
    }

    .通常ボタン span {
        display: flex;
        align-items: center;
    }

.コマンドウィンドウ {
    position: absolute;
    padding: 12px 17px;
    margin: 5px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -35%);
    text-align: center;
    max-height: 600px;
    overflow: scroll;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

    .コマンドウィンドウ::-webkit-scrollbar {
        display: none;
    }

    .コマンドウィンドウ .通常ボタン span {
        justify-content: center;
        white-space: nowrap;
        min-width:250px;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 全体の構造&lt;/h3&gt;
&lt;p&gt;このCSSは前回の「メッセージウィンドウを表示する方法」に「コマンドウィンドウ」クラスと「通常ボタン」クラスを追加しており、それ以外はほぼ同じです。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. コマンドウィンドウ&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.コマンドウィンドウ {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -35%);
    text-align: center;
    ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;中央配置：&lt;/span&gt;top: 50%; left: 50%; transform: translate(-50%, -35%); によって画面中央に配置。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;最大高さ：&lt;/span&gt;600px以内に設定し、オーバーフロー時はスクロール。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. ボタン（.通常ボタン）&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.通常ボタン {
    font-size: var(--小文字サイズ);
    background-color: rgba(250, 250, 250, 0.1);
    border-radius: 5px;
    ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ボタンデザイン。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;背景：&lt;/span&gt;半透明の白と斜めのグラデーション。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;角丸：&lt;/span&gt;5pxの角を丸く。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ホバー効果：&lt;/span&gt;ボタンにマウスを載せると黄色に変化。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;commandWindow.js　-　コマンドウィンドウクラス&lt;/h2&gt;
&lt;p&gt;このクラスの目的：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;コマンド（ボタンを介して実行される選択肢）を表示するウィンドウを作成。&lt;/li&gt;
&lt;li&gt;選択肢をクリックすると適切な処理が実行される仕組みを提供。&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class コマンドウィンドウクラス {
    constructor(スクリーンセレクタ, コマンドウィンドウセレクタ) {
        this.スクリーン要素 = document.querySelector(スクリーンセレクタ);
        if (!this.スクリーン要素) throw new Error(`スクリーンセレクタ:'${スクリーンセレクタ}'が見つかりません`);

        this.コマンドウィンドウ要素 = this.スクリーン要素.querySelector(コマンドウィンドウセレクタ);
        if (!this.コマンドウィンドウ要素) throw new Error(`コマンドウィンドウセレクタ:'${コマンドウィンドウセレクタ}'が見つかりません`);

        this.ボタン要素リスト = this.コマンドウィンドウ要素.querySelectorAll('button');
        if (!this.ボタン要素リスト.length) throw new Error(`'${コマンドウィンドウセレクタ}'にbuttonタグが見つかりません`);

        this.名称要素リスト = this.コマンドウィンドウ要素.querySelectorAll('span');
        if (!this.名称要素リスト.length) throw new Error(`'${コマンドウィンドウセレクタ}'にspanタグが見つかりません`);

        this.ボタン要素リスト.forEach(x =&amp;gt; x.onclick = this.ボタンをクリックする.bind(this));
    }

    async 表示する(コマンドリスト) {
        for (let i = 0; i &amp;lt; this.名称要素リスト.length; i++) {
            if (コマンドリスト.length &amp;lt;= i) {
                this.ボタン要素リスト[i].classList.toggle('消去', true);
                continue;
            }
            this.ボタン要素リスト[i].classList.toggle('消去', false);
            this.名称要素リスト[i].innerHTML = コマンドリスト[i].名称;
        }
        this.コマンドリスト = コマンドリスト;
        this.コマンドウィンドウ要素.classList.toggle('消去', false);
        this.以前のクリックハンドラ = this.スクリーン要素.onclick;
        this.スクリーン要素.onclick = this.ウィンドウ外をクリックする.bind(this);
        return new Promise(resolve =&amp;gt; this.resolve = resolve);
    }

    async ウィンドウ外をクリックする() {
        this.コマンドウィンドウ要素.classList.toggle('消去');
    }

    async ボタンをクリックする(event) {
        this.コマンドウィンドウ要素.classList.toggle('消去', true);
        event.stopPropagation();
        this.スクリーン要素.onclick = this.以前のクリックハンドラ;
        this.resolve(this.コマンドリスト[Number(event.currentTarget.value)].id);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. constructor() コンストラクタ&lt;/h3&gt;
&lt;p&gt;この部分は、クラスのインスタンスが作られるときに最初に呼び出されます。ウィンドウやボタンなどのHTML要素を取得し、操作できるようにします。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スクリーンセレクタ：&lt;/span&gt;コマンドウィンドウが配置される「画面」を示すセレクタ（CSSセレクタの指定）。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コマンドウィンドウセレクタ：&lt;/span&gt;コマンドを表示する「ウィンドウ」のセレクタ。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;処理の流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;this.スクリーン要素 に「画面」要素を取得。&lt;/li&gt;
&lt;li&gt;this.コマンドウィンドウ要素 に「コマンドウィンドウ」を取得。&lt;/li&gt;
&lt;li&gt;ウィンドウ内のボタンタグ（&amp;lt;button&amp;gt;）や名前を表示するスパンタグ（&amp;lt;span&amp;gt;）をリストとして取得。&lt;/li&gt;
&lt;li&gt;各ボタンにクリックイベントを設定しておく（「this.ボタンをクリックする」を登録）。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;各ステップで、要素が見つからない場合はエラーとして処理を終了します（例：ボタンがない場合）&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 表示する(コマンドリスト) メソッド&lt;/h3&gt;
&lt;p&gt;このメソッドは、コマンドウィンドウにコマンドを表示し、選択肢をユーザーに提示します。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;処理の流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コマンドリストを反映：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;入力されたコマンドリストに基づいて、ボタンと名前を表示。&lt;/li&gt;
&lt;li&gt;リストの長さが不足している場合、そのボタンを隠す。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ウィンドウを表示：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;コマンドウィンドウのCSSクラス消去（非表示状態）を削除。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クリックハンドラの変更：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;ウィンドウ外（背景など）をクリックすると閉じる処理を登録。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;Promise：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;選択が完了したら、その結果（id）を返す仕組みになっています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;Promise は、非同期処理が完了するまで待つ仕組みを提供します&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. ウィンドウ外をクリックする() メソッド&lt;/h3&gt;
&lt;p&gt;ウィンドウ外の画面部分がクリックされたとき、コマンドウィンドウを非表示にします。 （例：ユーザーが選択せずに閉じたいときの処理）&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. ボタンをクリックする(event) メソッド&lt;/h3&gt;
&lt;p&gt;ボタンがクリックされたときの処理を担当します。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;処理の流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ウィンドウを非表示に変更。&lt;/li&gt;
&lt;li&gt;イベントを伝播しないようにevent.stopPropagation()を呼び出し。&lt;/li&gt;
&lt;li&gt;前のクリックハンドラ（画面のクリックイベントなど）を復元。&lt;/li&gt;
&lt;li&gt;選択されたボタンの値（id）をPromiseで返す。&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;sample.js　-　サンプルクラス&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { レイヤークラス } from './layer.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート
import { メッセージウィンドウクラス } from './messageWindow.js'; // クラスをインポート
import { コマンドウィンドウクラス } from './commandWindow.js'; // クラスをインポート
import { Data } from './data.js'; // クラスをインポート
import { スプライトクラス } from './sprite.js'; // クラスをインポート

export class サンプル {
    static async main() {
        await サンプル.使用する画像を読み込む();
        サンプル.ループ処理を作成する();
        サンプル.メッセージウィンドウを作成する();
        サンプル.コマンドウィンドウを作成する();
        サンプル.レイヤーを作成する();
        サンプル.読み込んだ画像でスプライトを作成する();
        サンプル.作成した物を使って画面に表示する();
    }

    static async 使用する画像を読み込む() {
        const 画像情報リスト = [
            { id: '町', src: 'img/bg02.jpg' },
            { id: 'プレイヤー', src: 'img/chara01.png' }
        ];
        サンプル.画像管理 = new 画像管理クラス();
        await サンプル.画像管理.画像を読み込む(画像情報リスト);
    }

    static ループ処理を作成する() {
        ループ.初期化する();
        ループ.開始する();
    }

    static メッセージウィンドウを作成する() {
        サンプル.メッセージウィンドウ = new メッセージウィンドウクラス(&quot;.スクリーン&quot;, &quot;.メッセージウィンドウ&quot;);
        Data.オブジェクト管理[&quot;サンプル&quot;] = サンプル;
    }

    static コマンドウィンドウを作成する() {
        サンプル.コマンドウィンドウ = new コマンドウィンドウクラス(&quot;.スクリーン&quot;, &quot;.コマンドウィンドウ&quot;);
    }

    static レイヤーを作成する() {
        サンプル.レイヤー1 = new レイヤークラス('canvas.レイヤー1'); // 背景用のレイヤ
        サンプル.レイヤー2 = new レイヤークラス('canvas.レイヤー2'); // 前景用のレイヤ
        サンプル.レイヤー2.描画処理をループ処理に追加する();
    }

    static 読み込んだ画像でスプライトを作成する() {
        サンプル.背景01 = new スプライトクラス(サンプル.レイヤー1, サンプル.画像管理.取得する('町'), 0, 0, 640, 640);
        サンプル.人物01 = new スプライトクラス(サンプル.レイヤー2, サンプル.画像管理.取得する('プレイヤー'), 0, 0, 640, 640);
        サンプル.人物01正位置 = { x: サンプル.人物01.x, y: サンプル.人物01.y };
        サンプル.人物01.座標を設定する(640, 0, 1280, 640); //初期表示位置を設定する
    }

    static async 作成した物を使って画面に表示する() {
        サンプル.背景01.描画する();
        await サンプル.人物01.移動してフェードインする(-10, 0, サンプル.人物01正位置.x, 0, 1);
        ループ.処理を削除する(サンプル.レイヤー2);
        await サンプル.メッセージウィンドウ.表示する();
        await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;プレイヤーは町の広場に来た&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);

        let id = 0;
        while (1) {
            await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;どうする？&quot;);
            id = await サンプル.コマンドウィンドウ.表示する([
                { id: 0, 名称: &quot;話す&quot; },
                { id: 1, 名称: &quot;持物を見る&quot; },
                { id: 2, 名称: &quot;移動する&quot; }
            ]);
            if (id == 0) {
                await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;話が聞けそうな人は誰もいない&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
                continue;
            } else if (id==1) {
                await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;今のところ、何も持っていない&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
                continue;
            }

            await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;どこへ行く？&quot;);
            id = await サンプル.コマンドウィンドウ.表示する([
                { id: 0, 名称: &quot;やめる&quot; },
                { id: 1, 名称: &quot;武器屋へ行く&quot; },
                { id: 2, 名称: &quot;防具屋へ行く&quot; },
                { id: 3, 名称: &quot;道具屋へ行く&quot; },
                { id: 4, 名称: &quot;宿屋へ行く&quot; },
                { id: 5, 名称: &quot;町を出る&quot; }
            ]);
            if (id == 0) continue;
            else if (id == 1) {
                await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;武器屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
                continue;
            } else if (id == 2) {
                await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;防具屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
                continue;
            } else if (id == 3) {
                await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;道具屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
                continue;
            } else if (id == 4) {
                await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;宿屋は開いていないようだ&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
                continue;
            }
            await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;まだ装備が整っていない&amp;lt;w&amp;gt;10&amp;lt;/w&amp;gt;&quot;);
        }
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. プログラムの全体像&lt;/h3&gt;
&lt;p&gt;このコードの目的は次の通り：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;必要な画像を読み込み、それを画面に表示する。&lt;/li&gt;
&lt;li&gt;ユーザーが選択肢（コマンドウィンドウ）を選んで進行できる仕組みを提供する。&lt;/li&gt;
&lt;li&gt;メッセージウィンドウを使って物語や状況を表示する。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 必要なクラスのインポート&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;この部分で外部ファイル（モジュール）からクラスを読み込みます。
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js';
import { レイヤークラス } from './layer.js';
&lt;/code&gt;&lt;/pre&gt;
読み込まれたクラスは、このプログラムの中で使用されます。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. メイン処理 (main メソッド)&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;このプログラムのスタート地点です。&lt;/li&gt;
&lt;li&gt;次の手順でゲームの準備を整えます：&lt;ol class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;必要な画像をロードする。&lt;/li&gt;
&lt;li&gt;ゲームループ（繰り返し処理）を開始する。&lt;/li&gt;
&lt;li&gt;メッセージウィンドウやコマンドウィンドウを作成する。&lt;/li&gt;
&lt;li&gt;読み込んだ画像を使ってスプライト（キャラクターや背景）を画面に描画する。&lt;/li&gt;
&lt;li&gt;描画された画面に基づいてメッセージと選択肢を表示する。&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. 画像読み込み (使用する画像を読み込む メソッド)&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;使用する画像のリスト（例：「町」や「プレイヤー」）を準備し、それを読み込みます。&lt;/li&gt;
&lt;li&gt;読み込まれた画像は 画像管理クラス に保存され、後から使うことができます。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;5. レイヤーの作成 (レイヤーを作成する メソッド)&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;レイヤーはゲーム画面の「背景」と「前景」を分けるために使います。&lt;/li&gt;
&lt;li&gt;たとえば：
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;背景（レイヤー1）は町の画像を表示。&lt;/li&gt;
&lt;li&gt;前景（レイヤー2）はキャラクターや移動する物を表示。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;6. スプライトの作成 (読み込んだ画像でスプライトを作成する メソッド)&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;スプライトは画面に表示される画像（例：背景やキャラクター）のこと。&lt;/li&gt;
&lt;li&gt;このメソッドでは以下を設定します：
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;背景スプライト：町の画像を表示。&lt;/li&gt;
&lt;li&gt;キャラクタースプライト：「プレイヤー」の初期位置を設定。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;7. メッセージウィンドウの作成&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;メッセージを表示するためのウィンドウ（吹き出しのようなもの）を作ります。&lt;/li&gt;
&lt;li&gt;たとえば「プレイヤーは町の広場に来た」という物語を表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;8. コマンドウィンドウの作成&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;画面に「話す」「持物を見る」「移動する」などの選択肢を表示するウィンドウを用意します。&lt;/li&gt;
&lt;li&gt;プレイヤーが選択肢をクリックすると、それに対応する処理が実行されます。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;9. プログラムの流れ&lt;/h3&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;背景とキャラクターを表示：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画面に背景とキャラクター画像を描画します。&lt;/li&gt;
&lt;li&gt;キャラクターはフェードイン（徐々に表示）します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージを表示：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;メッセージウィンドウに「プレイヤーは町の広場に来た」などの文章を表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;コマンドの選択：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;プレイヤーが選択肢をクリックし、次の行動を決めます。&lt;/li&gt;
&lt;li&gt;たとえば、「話す」を選ぶと「話が聞けそうな人は誰もいない」と表示されます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;繰り返し処理：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;どの選択肢を選んでも、また次の選択肢が表示されます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907707&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907707&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907707&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;&lt;/div&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E9%81%B8%E6%8A%9E%E8%82%A2%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>メッセージウィンドウを表示する方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;以下のようなメッセージウィンドウを表示する方法を記します。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;一定時間ごとに1文字づつ表示します。&lt;/li&gt;
&lt;li&gt;メッセージを表示中に画面内をクリックすると一括で表示します。&lt;/li&gt;
&lt;li&gt;メッセージ内に以下のような制御を入れることが出来ます。&lt;ol class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;改行：&lt;/span&gt;メッセージを途中で改行します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クリア：&lt;/span&gt;メッセージを好きな箇所でクリアします。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クリック待ち：&lt;/span&gt;メッセージ表示をクリックされるか指定した時間まで停止します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;変数：&lt;/span&gt;変数を埋め込むことで、メッセージを使いまわすことができます。サンプルでは時刻の表示に変数を使っています。&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;670&quot; height=&quot;730&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample05/index.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;ファイル構成&lt;/h2&gt;
&lt;p&gt;ファイルとそれを入れるフォルダーを以下のような構成します。&lt;br /&gt;
※前回と同じファイル名でも内容が変わっている場合があります。&lt;br /&gt;
※背景と人物の画像はBing Image Creatorで生成しています（AI生成）。&lt;/p&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample05&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/index.html&quot; target=&quot;_blank&quot;&gt;index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/messageWindow.js&quot; target=&quot;_blank&quot;&gt;messageWindow.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/data.js&quot; target=&quot;_blank&quot;&gt;data.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/com.js&quot; target=&quot;_blank&quot;&gt;com.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/layer.js&quot; target=&quot;_blank&quot;&gt;layer.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/js/loop.js&quot; target=&quot;_blank&quot;&gt;loop.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;css&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/css/sample.css&quot; target=&quot;_blank&quot;&gt;sample.css&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/img/bg02.jpg&quot; target=&quot;_blank&quot;&gt;bg02.jpg　※背景画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample05/img/chara01.png&quot; target=&quot;_blank&quot;&gt;chara01.png　※人物画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;index.html　-　HTML&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang=&quot;ja&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=660,user-scalable=no,shrink-to-fit=yes&quot;&amp;gt;
    &amp;lt;title&amp;gt;メッセージウィンドウを作成する方法&amp;lt;/title&amp;gt;
    &amp;lt;link href=&quot;css/sample.css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;script type=&quot;module&quot; src=&quot;js/sample.js&quot;&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;aside class=&quot;画面更新情報&quot;&amp;gt;
        &amp;lt;p&amp;gt;
            リフレッシュレート：&amp;lt;span class=&quot;リフレッシュレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;Hz
            ／フレームレート：&amp;lt;span class=&quot;フレームレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;fps
        &amp;lt;/p&amp;gt;
    &amp;lt;/aside&amp;gt;
    &amp;lt;main class=&quot;スクリーン&quot;&amp;gt;
        &amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot; aria-label=&quot;グラフィックコンテンツ&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
        &amp;lt;article class=&quot;メッセージウィンドウ 消去 透明化&quot;&amp;gt;
            &amp;lt;p class=&quot;メッセージエリア&quot;&amp;gt;
                &amp;lt;span class=&quot;メッセージ&quot;&amp;gt;&amp;lt;/span&amp;gt;
                &amp;lt;span class=&quot;カーソル 点滅 不可視化&quot;&amp;gt;■&amp;lt;/span&amp;gt;
            &amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
    &amp;lt;/main&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. &amp;lt;head&amp;gt; セクション&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=660,user-scalable=no,shrink-to-fit=yes&quot;&amp;gt;
    &amp;lt;title&amp;gt;メッセージウィンドウを作成する方法&amp;lt;/title&amp;gt;
    &amp;lt;link href=&quot;css/sample.css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt; セクション：&lt;/span&gt;日本語を含む多言語を正しく表示するためにUTF-8を使用しています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;meta name=&quot;viewport&quot;&amp;gt; セクション：&lt;/span&gt;モバイル端末での表示を最適化するため、幅を660pxに固定し、ユーザーがズームできないよう設定しています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;title&amp;gt; セクション：&lt;/span&gt;ブラウザのタブに表示されるページタイトルです。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;link href=&quot;css/sample.css&quot; rel=&quot;stylesheet&quot;&amp;gt; セクション：&lt;/span&gt;別ファイル（css/sample.css）からスタイル情報を読み込む設定です。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. &amp;lt;body&amp;gt; セクション&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;script type=&quot;module&quot; src=&quot;js/sample.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;type=&quot;module&quot;：&lt;/span&gt;モジュール化されたJavaScriptファイルを読み込みます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;src=&quot;js/sample.js&quot;：&lt;/span&gt;読み込む外部JavaScriptファイルを設定しています。このスクリプトにはメッセージウィンドウの動作等が定義されています。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. 画面の更新情報&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;aside class=&quot;画面更新情報&quot;&amp;gt;
    &amp;lt;p&amp;gt;
        リフレッシュレート：&amp;lt;span class=&quot;リフレッシュレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;Hz
        ／フレームレート：&amp;lt;span class=&quot;フレームレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;fps
    &amp;lt;/p&amp;gt;
&amp;lt;/aside&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;役割：&lt;/span&gt;ここでは、画面の更新状況（リフレッシュレートとフレームレート）を表示しています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クラス名の設定：&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&quot;画面更新情報&quot;：&lt;/span&gt;全体のコンテナのスタイリング（例：中央揃えやフォントサイズなど）に対応。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&quot;リフレッシュレート&quot; や &quot;フレームレート&quot;：&lt;/span&gt;動的に数値が書き換えられる部分となります。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. スクリーンエリア&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;main class=&quot;スクリーン&quot;&amp;gt;
    &amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot; aria-label=&quot;グラフィックコンテンツ&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
    &amp;lt;article class=&quot;メッセージウィンドウ 消去 透明化&quot;&amp;gt;
        &amp;lt;p class=&quot;メッセージエリア&quot;&amp;gt;
            &amp;lt;span class=&quot;メッセージ&quot;&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;span class=&quot;カーソル 点滅 不可視化&quot;&amp;gt;■&amp;lt;/span&amp;gt;
        &amp;lt;/p&amp;gt;
    &amp;lt;/article&amp;gt;
&amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;Canvas要素：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot; aria-label=&quot;グラフィックコンテンツ&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;Canvasタグ：&lt;/span&gt;描画エリアを提供します。このコードでは画像やスプライトを表示する「レイヤー」として使われます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;属性：&lt;/span&gt;
&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;class=&quot;レイヤー1&quot;：&lt;/span&gt;CSSやJavaScriptで制御するためのクラス名。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;width=&quot;640&quot; height=&quot;640&quot;：&lt;/span&gt;Canvasの横幅と高さを指定。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;aria-label=&quot;グラフィックコンテンツ&quot;：&lt;/span&gt;アクセシビリティのためにコンテンツの説明を付けています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウ：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;article class=&quot;メッセージウィンドウ 消去 透明化&quot;&amp;gt;
    &amp;lt;p class=&quot;メッセージエリア&quot;&amp;gt;
        &amp;lt;span class=&quot;メッセージ&quot;&amp;gt;&amp;lt;/span&amp;gt;
        &amp;lt;span class=&quot;カーソル 点滅 不可視化&quot;&amp;gt;■&amp;lt;/span&amp;gt;
    &amp;lt;/p&amp;gt;
&amp;lt;/article&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;article class=&quot;メッセージウィンドウ 消去 透明化&quot;&amp;gt;：&lt;/span&gt;
&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;「メッセージウィンドウ」クラス：&lt;/span&gt;このクラスは、吹き出しやダイアログのように画面上にメッセージを表示するためのウィンドウのスタイルを定義しています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;「消去」クラス：&lt;/span&gt;CSS では display: none; として定義され、初期状態ではウィンドウが存在しているものの画面には表示されません。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;「透明化」クラス：&lt;/span&gt;CSS では opacity: 0; の設定になっており、見た目を透明にして隠しています。 ※「消去」と「透明化」を組み合わせて、ウィンドウを非表示状態にセットしています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;p class=&quot;メッセージエリア&quot;&amp;gt;：&lt;/span&gt;メッセージテキストが表示される領域です。CSS によりスクロールなどの設定がされています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;span class=&quot;メッセージ&quot;&amp;gt;：&lt;/span&gt;実際のメッセージテキストを 1 文字ずつ追加して表示していく部分です。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;span class=&quot;カーソル 点滅 不可視化&quot;&amp;gt;：&lt;/span&gt;
&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;「カーソル」クラス：&lt;/span&gt;メッセージ表示時に、クリック待ちを示すためのアイコン（ここでは■）の表示に使います。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;「点滅」クラス：&lt;/span&gt;CSS の @keyframes 点滅 や animation 設定を使って、「■」が点滅するアニメーションが適用されます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;「不可視化」クラス：&lt;/span&gt;CSS では visibility: hidden; として定義され、初期状態でカーソル自体が見えないようにしています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;sample.css　-　CSS&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;:root {
    --通常文字サイズ: 26px;
    --通常文字行高さ: 38px;
    --小文字サイズ: 18px;
    --小文字行高さ: 24px;
    --黒い影: 1px 1px 1px #000, -1px -1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, 2px 0px 1px #000, -2px -0px 1px #000, 0px 2px 1px #000, 0px -2px 1px #000;
    --トランジションスピード: 0.8s;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior-y: none;
}

.画面更新情報 {
    text-align: center;
    font-size: var(--小文字サイズ);
    line-height: var(--小文字行高さ);
    color: #333;
}

.スクリーン {
    width: 640px;
    height: 640px;
    margin: 20px auto;
    border: 2px solid #ccc;
    position: relative;
    background-color: black;
}

canvas {
    position: absolute;
}

.不可視化 {
    visibility: hidden;
}

.透明化 {
    opacity: 0;
}

.消去 {
    display: none;
}

.表示 {
    display: block;
}

@keyframes 点滅 {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.点滅 {
    animation: 点滅 1s ease-out infinite;
}

.メッセージウィンドウ {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    border: solid 3px white;
    padding: 12px 17px;
    margin: 5px;
    transition: opacity var(--トランジションスピード) ease-out;
}

    .メッセージウィンドウ .メッセージエリア {
        padding: 3px;
        margin: 0px;
        font-size: var(--通常文字サイズ);
        line-height: var(--通常文字行高さ);
        color: white;
        text-shadow: var(--黒い影);
        width: 584px;
        height: 154px;
        overflow: scroll;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

        .メッセージウィンドウ .メッセージエリア::-webkit-scrollbar {
            display: none;
        }

    .メッセージウィンドウ .カーソル {
        font-size: var(--通常文字サイズ);
        display: inline-block;
        transform: translateY(-2px);
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 変数（:rootセクター）&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;:root {
    --通常文字サイズ: 26px;
    --通常文字行高さ: 38px;
    --小文字サイズ: 18px;
    --小文字行高さ: 24px;
    --黒い影: 1px 1px 1px #000, -1px -1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, 2px 0px 1px #000, -2px -0px 1px #000, 0px 2px 1px #000, 0px -2px 1px #000;
    --トランジションスピード: 0.8s;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;ここでは CSS 変数を定義しています。たとえば、文章の基本サイズや行の高さ、テキストに付ける影、アニメーションの速さなど、後で何度も使う数値を 1か所で管理できるようにしています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;例：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;--通常文字サイズ は 26px に設定されており、通常のテキストサイズとして使用。&lt;/li&gt;
&lt;li&gt;--黒い影 は、文字を際立たせるために複数の影を短いオフセットとともに定義しています。&lt;/li&gt;
&lt;li&gt;--トランジションスピード はアニメーションや状態変化の際の速度（ここでは 0.8秒）を指定しています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 全体の設定（bodyセレクター）&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior-y: none;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;ページ全体の基本となるスタイルを設定しています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;全体のデザイン：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;font-family：&lt;/span&gt;フォントの種類を指定。Arialがメイン。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;margin と padding：&lt;/span&gt;0 にすることで、ブラウザの初期余白をリセット。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;background-color：&lt;/span&gt;薄いグレー（#f4f4f4）で全体の背景色に指定。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;特殊な設定：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;-webkit-tap-highlight-color：&lt;/span&gt;スマホでタップしたときのハイライトを無効化。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;overscroll-behavior-y：&lt;/span&gt;スクロールの挙動を制御することで、特にスマートフォンなどでの意図しない操作を防いでいます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. 更新情報のスタイル（.画面更新情報）&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.画面更新情報 {
    text-align: center;
    font-size: var(--小文字サイズ);
    line-height: var(--小文字行高さ);
    color: #333;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;更新情報（リフレッシュレートやフレームレート）の文字を中央揃えにし、小さなフォントサイズで表示しています。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. スクリーンエリアの設定（.スクリーン）&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.スクリーン {
    width: 640px;
    height: 640px;
    margin: 20px auto;
    border: 2px solid #ccc;
    position: relative;
    background-color: black;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;画面のメイン表示部分となるエリアのスタイル設定です。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;width &amp;amp; height：&lt;/span&gt;幅と高さを640pxずつ固定。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;margin: 20px auto：&lt;/span&gt;上下に20pxの余白を作り、中央に配置。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;border：&lt;/span&gt;灰色（#ccc）の2px枠線を追加。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;background-color：&lt;/span&gt;背景を黒に設定。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;position: relative：&lt;/span&gt;内部に配置する要素（たとえば canvas やメッセージウィンドウ）の絶対配置の基準となります。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;5. Canvas（キャンバス）の設定&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;canvas {
    position: absolute;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;描画領域として利用する canvas 要素を絶対配置にしています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;これにより、canvas は親要素（ここでは .スクリーン）の中で自由に配置できるようになります。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;6. 表示や非表示を制御するクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.不可視化 {
    visibility: hidden;
}

.透明化 {
    opacity: 0;
}

.消去 {
    display: none;
}

.表示 {
    display: block;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;HTML 要素の表示状態を切り替えるための便利なクラスを定義しています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;違い：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;.不可視化：&lt;/span&gt;visibility: hidden; は、その領域はレイアウトに残るが見えなくなる。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;.透明化：&lt;/span&gt;opacity: 0; は、要素が透明になり見えなくなるが、クリックなどのイベントは受ける場合もある。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;.消去：&lt;/span&gt;display: none; は、要素自体を完全に除去してレイアウトに影響を与えない。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;.表示：&lt;/span&gt;display: block; は、要素を改めてブロック表示させます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;7. 点滅アニメーションの定義&lt;/h3&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;7.1 キーフレームの定義&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;@keyframes 点滅 {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;点滅のアニメーションです。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;0%（開始時）と 100%（終了時）の時点で透明度 opacity が 1 ＝完全に表示&lt;/li&gt;
&lt;li&gt;50% の時点で透明度が 0 ＝完全に消える&lt;/li&gt;
&lt;li&gt;これにより、要素が周期的に現れたり消えたりします&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;7.2 点滅クラスの適用&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.点滅 {
    animation: 点滅 1s ease-out infinite;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;このクラスを要素につけると、先ほど定義した点滅のアニメーションが適用されます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;animation：&lt;/span&gt;点滅 1s ease-out infinite;
&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;アニメーション名は「点滅」&lt;/li&gt;
&lt;li&gt;アニメーション期間は 1 秒&lt;/li&gt;
&lt;li&gt;ease-out により、終了に向かってゆっくり変化する効果&lt;/li&gt;
&lt;li&gt;infinite で繰り返し無限に実行&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;8. メッセージウィンドウの設定&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.メッセージウィンドウ {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    border: solid 3px white;
    padding: 12px 17px;
    margin: 5px;
    transition: opacity var(--トランジションスピード) ease-out;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウ全体のデザイン：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;背景：&lt;/span&gt;半透明の黒（rgba(0, 0, 0, 0.7)）。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;枠線：&lt;/span&gt;白色の3px枠線。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;アニメーション：&lt;/span&gt;transition により透明度（opacity）を滑らかに変化させる。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;8.1 メッセージエリア&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.メッセージウィンドウ .メッセージエリア {
    padding: 3px;
    margin: 0px;
    font-size: var(--通常文字サイズ);
    line-height: var(--通常文字行高さ);
    color: white;
    text-shadow: var(--黒い影);
    width: 584px;
    height: 154px;
    overflow: scroll;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.メッセージウィンドウ .メッセージエリア::-webkit-scrollbar {
    display: none;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;文字デザイン：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;font-size と line-height は設定済みの変数を使用。&lt;/li&gt;
&lt;li&gt;白色の文字（color: white）に影（text-shadow）を追加。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スクロールバー非表示：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;overflow: scroll; により、テキストがあふれる場合はスクロールできるように設定。ただし、IE と Firefox のスクロールバーは none で非表示にしています。&lt;/li&gt;
&lt;li&gt;また、WebKit系ブラウザではスクロールバーを完全に非表示にする設定も追加。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;8.2 カーソル（■）の設定&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;.メッセージウィンドウ .カーソル {
    font-size: var(--通常文字サイズ);
    display: inline-block;
    transform: translateY(-2px);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;メッセージウィンドウ内の「カーソル」要素（■）をスタイリングします。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;transform: translateY(-2px); は、カーソルがテキストの高さに合わせて少し位置調整されるための設定です。&lt;/li&gt;
&lt;li&gt;先ほどの「点滅」クラスを付けると、点滅するカーソルとして動作させることができます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;com.js　-　共通処理クラス&lt;/h2&gt;
&lt;p&gt;Com クラス は共通で使用できる処理をまとめています。&lt;br /&gt;
一時停止と時間フォーマットの２つがあります。&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class Com {
    static 一時停止(時間) {
        return new Promise(resolve =&amp;gt; setTimeout(resolve, 時間 * 1000));
    }

    static シリアル値を時分秒に変換する(シリアル値) {
        // シリアル値をDateオブジェクトに変換
        const date = new Date(シリアル値);

        // 時間、分、秒を取得
        const hours = date.getHours();
        const minutes = date.getMinutes();
        const seconds = date.getSeconds();

        // フォーマットして返す
        return `${hours}時${minutes}分${seconds}秒`;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 一時停止(時間) メソッド&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;役割：&lt;/span&gt;指定した時間だけプログラムを停止する機能を提供します。例えば、ゲームやタイマー機能で使われることがあります。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;仕組み：&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;setTimeout という JavaScriptの関数を利用して、一時停止を実現します。&lt;/li&gt;
&lt;li&gt;setTimeout は、第2引数で指定した時間が経過した後に、第1引数で指定した関数をコールします。&lt;/li&gt;
&lt;li&gt;Promise を使って、停止が終わった後に次の処理を続けられるようにしています。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;コードの流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;setTimeout を使って指定した時間（秒&amp;times;1000ミリ秒）だけ待ちます。&lt;/li&gt;
&lt;li&gt;待ち時間が終わったら resolve で「再開していいよ」と合図します。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. シリアル値を時分秒に変換する(シリアル値) メソッド&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;役割：&lt;/span&gt;シリアル値（数値形式の時刻）を、「〇〇時〇〇分〇〇秒」という形に変換して表示します。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;仕組み：&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;JavaScript の Date オブジェクトを利用してシリアル値を時間に変換します。&lt;/li&gt;
&lt;li&gt;変換された日時から「時」「分」「秒」を取り出します。&lt;/li&gt;
&lt;li&gt;最後にフォーマットして使いやすい形（日本語の時刻表記）にします。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;コードの流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;new Date(シリアル値) でシリアル値を日時オブジェクトに変換します。&lt;/li&gt;
&lt;li&gt;getHours、getMinutes、getSeconds でそれぞれ「時」「分」「秒」を取得します。&lt;/li&gt;
&lt;li&gt;フォーマットして、「〇〇時〇〇分〇〇秒」の形で返します。&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;data.js　-　データ管理クラス&lt;/h2&gt;
&lt;p&gt;この Data クラスは、文字列に埋め込まれた &amp;lt;var&amp;gt;変数名&amp;lt;/var&amp;gt; の形式で記述された変数を、事前に登録されたデータ（オブジェクト管理）から値を引き出して置き換えます。&lt;br /&gt;
イメージとしては、テンプレートに変数名を埋め込んでおき、実行時にそれを動的に値へ変える仕組みです。&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class Data {
    static オブジェクト管理 = {};

    static 文字列内の変数を値に変換する(文字列) {
        let 変換結果 = 文字列;
        const varList = 変換結果.match(/&amp;lt;var&amp;gt;[^&amp;lt;]*&amp;lt;\/var&amp;gt;/g);
        if (!varList) return 変換結果; // 変数が無い場合は何もせずにそのまま返す

        varList.forEach(varTag =&amp;gt; {
            const 変数名 = varTag.replace(/&amp;lt;var&amp;gt;([^&amp;lt;]*)&amp;lt;\/var&amp;gt;/, &quot;$1&quot;);
            const 値 = Data.変数の値を取得する(変数名);
            変換結果 = 変換結果.replace(varTag, 値); // &amp;lt;var&amp;gt;・・・&amp;lt;/var&amp;gt;を値に置き換える
        });
        return 変換結果;
    }

    static 変数の値を取得する(変数名) {
        const 名称リスト = 変数名.split(&quot;.&quot;);
        let 値 = Data.オブジェクト管理;

        for (const 名称 of 名称リスト) {
            値 = 値?.[名称];
            if (値 === undefined || 値 === null) return &quot;&quot;; // 値がない場合は空文字を使用
        }
        return 値;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. オブジェクト管理：静的プロパティ&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;static オブジェクト管理 = {};
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;このプロパティは「変数名と値」を管理するための大元のデータ構造です。&lt;/li&gt;
&lt;li&gt;登録されたデータを基に、変数名の値を検索します。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;例: もし オブジェクト管理 = { &quot;user&quot;: { &quot;name&quot;: &quot;プレイヤー&quot;, &quot;level&quot;: 25 } } となっている場合、user.name の値は &quot;プレイヤー&quot; となります。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 文字列内の変数を値に変換する：メソッド&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;役割：&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;入力：&lt;/span&gt;変換対象の文字列（例: &quot;こんにちは、&amp;lt;var&amp;gt;user.name&amp;lt;/var&amp;gt;さん！&quot;）&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;出力：&lt;/span&gt;変換結果の文字列（例: &quot;こんにちは、プレイヤーさん！&quot;）&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;コードの流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;変数タグを探す:&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const varList = 変換結果.match(/&amp;lt;var&amp;gt;[^&amp;lt;]*&amp;lt;\/var&amp;gt;/g);
&lt;/code&gt;&lt;/pre&gt;
この正規表現を使って &amp;lt;var&amp;gt;変数名&amp;lt;/var&amp;gt; の形を探し出します。例えば、&amp;lt;var&amp;gt;user.name&amp;lt;/var&amp;gt; が該当します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;変数名を取り出す:&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 変数名 = varTag.replace(/&amp;lt;var&amp;gt;([^&amp;lt;]*)&amp;lt;\/var&amp;gt;/, &quot;$1&quot;);
&lt;/code&gt;&lt;/pre&gt;
この処理で &amp;lt;var&amp;gt; と &amp;lt;/var&amp;gt; を取り除き、純粋な変数名（例: user.name）を取り出します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;値に置き換える:&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 値 = Data.変数の値を取得する(変数名);
変換結果 = 変換結果.replace(varTag, 値);
&lt;/code&gt;&lt;/pre&gt;
Data.変数の値を取得する メソッドで値を検索し、該当する場合は置き換えます。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. 変数の値を取得する：メソッド&lt;/h3&gt;
&lt;p&gt;このメソッドは、「変数名の構造」を辿りながら オブジェクト管理 の中から適切な値を見つけ出します。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;コードの流れ：&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;変数名を分割:&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 名称リスト = 変数名.split(&quot;.&quot;);
&lt;/code&gt;&lt;/pre&gt;
例えば、user.name なら [&quot;user&quot;, &quot;name&quot;] に分解されます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;値を辿る:&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;値 = 値?.[名称];
&lt;/code&gt;&lt;/pre&gt;
名前リストを順番に参照しながらネストされた構造を探索します。
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;例：&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;オブジェクト管理 = { &quot;user&quot;: { &quot;name&quot;: &quot;プレイヤー&quot; } }&lt;/li&gt;
&lt;li&gt;変数名 = &quot;user.name&quot;&lt;/li&gt;
&lt;li&gt;処理結果: &quot;プレイヤー&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;値が存在しなければ空文字を返す:&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;if (値 === undefined || 値 === null) return &quot;&quot;;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. 全体の動作イメージ&lt;/h3&gt;
&lt;p&gt;例えば、以下のように使われます：&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;Data.オブジェクト管理 = {
    user: { name: &quot;プレイヤー&quot;, level: 25 },
    system: { time: &quot;12:00&quot; }
};

const result = Data.文字列内の変数を値に変換する(
    'こんにちは、&amp;lt;var&amp;gt;user.name&amp;lt;/var&amp;gt;さん。現在の時刻は&amp;lt;var&amp;gt;system.time&amp;lt;/var&amp;gt;です。'
);

console.log(result);
// 結果: &quot;こんにちは、プレイヤーさん。現在の時刻は12:00です。&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;messageWindow.js　-　メッセージウィンドウクラス&lt;/h2&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { Data } from './data.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート
import { Com } from './com.js'; // クラスをインポート

class 制御情報クラス {
    constructor(メッセージ, メッセージエリア要素) {
        this.メッセージ = メッセージ;
        this.表示位置 = 0;
        this.表示メッセージ = &quot;&quot;;
        this.クリック待ちフラグ = false;
        this.表示フレームカウンタ = 0;
        this.クリック待ちフレームカウンタ = 0;
        this.スクロール高さ = メッセージエリア要素.scrollHeight;
        this.一括表示フラグ = false;
    }
}

export class メッセージウィンドウクラス {
    constructor(スクリーンセレクタ, メッセージウィンドウセレクタ, 出現時間 = 1.0
        , 表示フレーム間隔 = 2, クリック待ち時間 = 30) {
        this.スクリーン要素 = document.querySelector(スクリーンセレクタ);
        this.メッセージウィンドウ要素 = this.スクリーン要素.querySelector(メッセージウィンドウセレクタ);
        this.メッセージエリア要素 = this.メッセージウィンドウ要素.querySelector(&quot;.メッセージエリア&quot;);
        this.メッセージ要素 = this.メッセージエリア要素.querySelector(&quot;.メッセージ&quot;);
        this.カーソル要素 = this.メッセージエリア要素.querySelector(&quot;.カーソル&quot;);
        this.出現時間 = 出現時間;
        this.表示フレーム間隔 = 表示フレーム間隔;
        this.クリック待ちフレーム数 = this.基本クリック待ちフレーム数 = クリック待ち時間 &amp;gt; 0 ? ループ.フレームレート * クリック待ち時間 : 0;
    }

    メッセージを表示する(メッセージ) {
        const 制御情報 = new 制御情報クラス(Data.文字列内の変数を値に変換する(メッセージ), this.メッセージエリア要素);
        this.スクリーン要素.onclick = this.メッセージ表示時にクリックする.bind(this, 制御情報);
        return new Promise(resolve =&amp;gt; {
            ループ.処理を追加する(this, () =&amp;gt; {
                if (this.クリック待ち時の処理を行う(制御情報)) return;

                // 表示フレーム間隔でメッセージを表示する
                if (0 &amp;lt; 制御情報.表示フレームカウンタ--) return;
                制御情報.表示フレームカウンタ = this.表示フレーム間隔;

                // 指定されたメッセージを全て表示したら処理を終了する
                if (制御情報.表示位置 &amp;gt;= 制御情報.メッセージ.length) {
                    ループ.処理を削除する(this);
                    this.スクリーン要素.onclick = null;
                    resolve();
                    return;
                }

                if (this.メッセージを一括で表示する(制御情報)) return;
                if (this.制御タグを取得する(制御情報)) return;
                this.指定した文字数のメッセージを表示する(制御情報, 1);
            });
        });
    }

    クリック待ち時の処理を行う(制御情報) {
        if (!制御情報.クリック待ちフラグ) return false;

        // クリック待ち時間（クリック待ちフレーム数）が0の場合は無限にクリックを待つ
        if (!this.クリック待ちフレーム数) return true;

        // クリック待ち時間までクリックを待つ
        if (this.クリック待ちフレーム数 &amp;gt; 制御情報.クリック待ちフレームカウンタ++) return true;

        制御情報.クリック待ちフレームカウンタ = 0;
        this.クリック待ち時にクリックする(制御情報);
        return true;
    }

    メッセージを一括で表示する(制御情報) {
        if (!制御情報.一括表示フラグ) return false;

        // 制御タグまでの文字を一括で表示する
        let 表示文字数 = 制御情報.メッセージ.indexOf('&amp;lt;', 制御情報.表示位置) - 制御情報.表示位置;
        if (表示文字数 == 0) return false; // 次の文字が制御タグだった場合
        if (表示文字数 &amp;lt; 0) {
            // 制御タグが無い場合は最後まで表示する
            表示文字数 = 制御情報.メッセージ.length - 制御情報.表示位置;
        }
        this.指定した文字数のメッセージを表示する(制御情報, 表示文字数);
        return true;
    }

    指定した文字数のメッセージを表示する(制御情報, 文字数) {
        制御情報.表示メッセージ += 制御情報.メッセージ.substring(制御情報.表示位置, 制御情報.表示位置 + 文字数);
        制御情報.表示位置 += 文字数;
        this.メッセージ要素.innerHTML = 制御情報.表示メッセージ;
        if (制御情報.スクロール高さ == this.メッセージエリア要素.scrollHeight) return;
        this.メッセージエリア要素.scrollTop = 制御情報.スクロール高さ = this.メッセージエリア要素.scrollHeight;
        return;
    }

    制御タグを取得する(制御情報) {
        if (制御情報.メッセージ.charAt(制御情報.表示位置) != '&amp;lt;') return false;
        if (this.制御タグの処理を行う(制御情報, '&amp;lt;br&amp;gt;', () =&amp;gt; 制御情報.表示メッセージ += '&amp;lt;br&amp;gt;')) return true; // 改行する
        if (this.制御タグの処理を行う(制御情報, '&amp;lt;c&amp;gt;', () =&amp;gt; 制御情報.表示メッセージ = '')) return true; // クリアする
        if (this.クリック待ちにする(制御情報)) return true;
        return false;
    }

    制御タグの処理を行う(制御情報, タグ名, 処理) {
        if (!制御情報.メッセージ.startsWith(タグ名, 制御情報.表示位置)) return false;
        制御情報.表示位置 += タグ名.length;
        処理();
        this.メッセージ要素.innerHTML = 制御情報.表示メッセージ;
        return true;
    }

    クリック待ちにする(制御情報) {
        const タグ名 = '&amp;lt;w&amp;gt;';
        if (!制御情報.メッセージ.startsWith(タグ名, 制御情報.表示位置)) return false;
        const 取得メッセージ = 制御情報.メッセージ.substring(制御情報.表示位置);
        const wList = 取得メッセージ.match(/^&amp;lt;w&amp;gt;\d*&amp;lt;\/w&amp;gt;/);
        if (wList) {
            const 待ち時間 = Number(wList[0].replace(/&amp;lt;w&amp;gt;(\d*)&amp;lt;\/w&amp;gt;/, &quot;$1&quot;));
            制御情報.表示位置 += wList[0].length;
            this.クリック待ちフレーム数 = 待ち時間 &amp;gt; 0 ? ループ.フレームレート * 待ち時間 : 0;
        } else {
            制御情報.表示位置 += タグ名.length;
        }
        制御情報.クリック待ちフラグ = true;
        制御情報.一括表示フラグ = false;
        this.スクリーン要素.onclick = this.クリック待ち時にクリックする.bind(this, 制御情報);
        this.カーソル要素.classList.toggle('不可視化', false);
        return true;
    }

    クリック待ち時にクリックする(制御情報) {
        制御情報.クリック待ちフラグ = false;
        this.クリック待ちフレーム数 = this.基本クリック待ちフレーム数;
        this.カーソル要素.classList.toggle('不可視化' , true);
        this.スクリーン要素.onclick = this.メッセージ表示時にクリックする.bind(this, 制御情報);
    }

    メッセージ表示時にクリックする(制御情報) {
        制御情報.一括表示フラグ = true;
    }

    async 表示する() {
        this.メッセージウィンドウ要素.classList.replace('消去', '表示');
        await Com.一時停止(this.出現時間); // 少しずつ出現する時間
        this.メッセージウィンドウ要素.classList.toggle('透明化', false);
        await Com.一時停止(this.出現時間); // 出現した後に少し待つ
    }

    async 消去する() {
        this.メッセージウィンドウ要素.classList.toggle('透明化', true);
        this.メッセージウィンドウ要素.classList.replace('表示', '消去');
        this.メッセージ要素.innerHTML = &quot;&quot;;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. 全体の流れ&lt;/h3&gt;
&lt;p&gt;このコードは、以下の3つの主要なクラスを利用しています：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;Dataクラス：&lt;/span&gt;文字列内に変数を埋め込んで値を変換します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ループクラス：&lt;/span&gt;アニメーションや継続的な処理を管理します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;Comクラス：&lt;/span&gt;一時停止や時刻表示などの補助的な処理を提供します。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;さらに、以下の2つのクラスを新たに定義しています：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;制御情報クラス：&lt;/span&gt;メッセージを管理する内部データ構造。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウクラス：&lt;/span&gt;メッセージウィンドウの動作を管理します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. 制御情報クラス&lt;/h3&gt;
&lt;p&gt;このクラスは、文字表示の進捗状況を管理します。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;プロパティの内容：&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージ：&lt;/span&gt;「表示する全文字列」。 ※ここには、変数の値に変換された後のテキストが格納されます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;表示位置：&lt;/span&gt;現在、どこまで文字列を表示済みかのインデックスです。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;表示メッセージ：&lt;/span&gt;実際に画面上に表示中の文字列。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クリック待ちフラグ：&lt;/span&gt;制御タグ（例えば &amp;lt;w&amp;gt;）でクリック待ち状態になったときに true となります。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;表示フレームカウンタ：&lt;/span&gt;１文字表示するまでのフレーム間隔を管理するためのカウンタ。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クリック待ちフレームカウンタ：&lt;/span&gt;クリック待ちの時間（フレーム数）をカウントするためのもの。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スクロール高さ：&lt;/span&gt;メッセージエリアのスクロール位置を更新する必要があるかどうかを判断するため、初期のスクロール高さを記録します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一括表示フラグ：&lt;/span&gt;ユーザーが画面（スクリーン）をクリックすると、通常の１文字ずつの表示ではなく「一括表示」に切り替えるためのフラグです。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. メッセージウィンドウクラス&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;■ コンストラクタ&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;このクラスのコンストラクタでは、引数としてセレクタ（例えば、スクリーンおよびメッセージウィンドウの要素を指定する文字列）が渡されます。また、出現時間、１文字ずつ表示する際のフレーム間隔、クリック待ち時間（フレーム換算）を受け取ります。 処理の流れは以下のとおり：&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;DOM要素の取得：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画面全体を示す「スクリーン要素」&lt;/li&gt;
&lt;li&gt;その中の「メッセージウィンドウ要素」&lt;/li&gt;
&lt;li&gt;ウィンドウ内の「メッセージエリア」および「メッセージ」要素&lt;/li&gt;
&lt;li&gt;最後に、カーソル（点滅させる対象）の要素を取得&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;各種パラメータの保持：&lt;/span&gt;出現時間や表示フレーム間隔、そしてクリック待ちフレーム数（ループのフレームレート&amp;times;待ち時間）を設定しています。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. メッセージの表示処理&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;■ メッセージを表示する：メソッド&lt;/span&gt;&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;初期設定：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;渡されたメッセージ（変数の置換済みのテキスト）とメッセージエリア要素の情報をもとに、新しい 制御情報クラス のインスタンスを作成します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;クリックイベントの設定：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画面（スクリーン要素）をクリックすると、メッセージ表示時にクリックする メソッド（後述）で処理が走るようにします。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ループ処理の追加：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;外部のループ管理（requestAnimationFrame を利用している ループ クラス）に対して、このメッセージ表示処理関数を登録します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;各フレームでの動作：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;クリック待ちの場合は、クリックされるか指定した時間が経過するまで待機します。&lt;/li&gt;
&lt;li&gt;それ以外の場合、設定されたフレーム間隔ごとに表示する文字数を更新します。&lt;/li&gt;
&lt;li&gt;もし全メッセージが表示されていれば、ループ処理を削除して Promise を解決（終了）します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一括表示の確認：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;ユーザーのクリックによって一括表示フラグが true になっている場合は、通常の１文字ずつの表示ではなく、次の制御タグ（&amp;lt; で始まる部分）までのテキストを一気に表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;制御タグの処理：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;現在の位置が &amp;lt; なら、制御タグを取得する でタグ内容を処理します（たとえば &amp;lt;br&amp;gt; なら改行、&amp;lt;c&amp;gt; ならメッセージクリア、&amp;lt;w&amp;gt; ならクリック待ち）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;最後は１文字ずつ表示：&lt;/span&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;上記いずれにも該当しなければ、指定した文字数のメッセージを表示する メソッドで１文字だけ追加して表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;5. 制御タグの処理&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;■ 制御タグの例&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;br&amp;gt;：&lt;/span&gt;改行を挿入するタグ。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;処理関数により、表示中のメッセージに &amp;lt;br&amp;gt; を追加します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;c&amp;gt;：&lt;/span&gt;表示中のメッセージをクリアするタグ。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;このタグを検出すると、表示文字列を空文字にリセットします。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;&amp;lt;w&amp;gt;数字&amp;lt;/w&amp;gt;：&lt;/span&gt;クリック待ちタグ。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;ここではタグ内の数字を読み取り、その秒数分（ループのフレームレート&amp;times;秒数）のクリック待ち状態にします。&lt;/li&gt;
&lt;li&gt;同時に「クリック待ちフラグ」が true になり、カーソルの表示も切り替えられます（不可視を無効にする）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;6. ユーザークリックでの一括表示&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;■ メッセージ表示時にクリックする：メソッド&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ユーザーが画面（スクリーン）をクリックすると、通常は１文字ずつ表示されるところを、一括表示フラグを true に設定します。&lt;/li&gt;
&lt;li&gt;次のループ処理時に、メッセージを一括で表示する が呼ばれ、次の制御タグまでのテキストをまとめて表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;7. 表示・消去の演出&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;■ 表示する：メソッド&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;メッセージウィンドウを出現させる際に、CSS クラスを切り替えます。&lt;ol class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;初めは非表示状態（たとえば、消去 クラスが付いている）から、表示 クラスに切り替えます。&lt;/li&gt;
&lt;li&gt;その後、指定した出現時間だけ一時停止（Com.一時停止 を使用）し、さらに透明状態を解除（透明化 クラスの切替）して、ふわっと表示されるようにします。&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;bold&quot;&gt;■ 消去する：メソッド&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;表示されたメッセージウィンドウを非表示にするため、透明度を下げ、表示 クラスを 消去 に変更し、メッセージ内容をクリアします。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;sample.js　-　サンプルクラス&lt;/h2&gt;
&lt;p&gt;このプログラムは次のような処理を行います：&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;必要なクラスをインポートします。&lt;/li&gt;
&lt;li&gt;メイン処理 (main) を実行します。&lt;/li&gt;
&lt;li&gt;ループ処理や画面描画を初期化します。&lt;/li&gt;
&lt;li&gt;画像を読み込み、それを基にスプライトを作成します。&lt;/li&gt;
&lt;li&gt;作成したスプライトやメッセージウィンドウを表示します。&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { スプライトクラス } from './sprite.js'; // クラスをインポート
import { レイヤークラス } from './layer.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート
import { メッセージウィンドウクラス } from './messageWindow.js'; // クラスをインポート
import { Data } from './data.js'; // クラスをインポート
import { Com } from './com.js'; // クラスをインポート

class サンプル {
    static async main() {
        サンプル.ループ処理を作成する();
        サンプル.メッセージウィンドウを作成する();
        サンプル.レイヤーを作成する();
        if (!await サンプル.使用する画像を読み込む()) return;
        サンプル.読み込んだ画像でスプライトを作成する();
        サンプル.作成した物を使って画面に表示する();
    }

    static ループ処理を作成する() {
        ループ.初期化する();
        ループ.開始する();
    }

    static メッセージウィンドウを作成する() {
        サンプル.メッセージウィンドウ = new メッセージウィンドウクラス(&quot;.スクリーン&quot;, &quot;.メッセージウィンドウ&quot;);
        Data.オブジェクト管理[&quot;サンプル&quot;] = サンプル;
    }

    static レイヤーを作成する() {
        サンプル.レイヤー = new レイヤークラス('canvas.レイヤー1');
        ループ.処理を追加する(サンプル.レイヤー, サンプル.レイヤー.描画する.bind(サンプル.レイヤー));
    }

    static async 使用する画像を読み込む() {
        const 画像情報リスト = [
            { id: '町01', src: 'img/bg02.jpg' },
            { id: '人物01', src: 'img/chara01.png' }
        ];
        サンプル.画像管理 = new 画像管理クラス();
        return await サンプル.画像管理.画像を読み込む(画像情報リスト);
    }

    static 読み込んだ画像でスプライトを作成する() {
        サンプル.背景01 = new スプライトクラス(サンプル.レイヤー, サンプル.画像管理.取得する('町01'), 0, 0, 640, 640);
        サンプル.レイヤー.処理を追加する(サンプル.背景01, サンプル.背景01.描画する.bind(サンプル.背景01));
        サンプル.人物01 = new スプライトクラス(サンプル.レイヤー, サンプル.画像管理.取得する('人物01'), 0, 150, 640, 640);
        サンプル.人物01正位置 = { x: サンプル.人物01.x, y: サンプル.人物01.y };
        サンプル.人物01.座標を設定する(640, 150, 1280, 640); //初期表示位置を設定する
    }

    static async 作成した物を使って画面に表示する() {
        サンプル.主人公名 = &quot;プレイヤー&quot;;
        サンプル.現時刻 = Com.シリアル値を時分秒に変換する(Date.now());

        await サンプル.人物01.移動してフェードインする(-10, 0, サンプル.人物01正位置.x, 0, 1);
        ループ.処理を削除する(サンプル.レイヤー);

        await サンプル.メッセージウィンドウ.表示する();
        await サンプル.メッセージウィンドウ.メッセージを表示する(
    &quot;&amp;lt;var&amp;gt;サンプル.主人公名&amp;lt;/var&amp;gt;は町を訪れた&amp;lt;w&amp;gt;5&amp;lt;/w&amp;gt;&amp;lt;br&amp;gt;&amp;lt;c&amp;gt;&amp;lt;var&amp;gt;サンプル.主人公名&amp;lt;/var&amp;gt;はとりあえず町の人に今何時か聞いてみた&amp;lt;w&amp;gt;&amp;lt;br&amp;gt;すると「&amp;lt;var&amp;gt;サンプル.現時刻&amp;lt;/var&amp;gt;」だと教えてくれた&amp;lt;w&amp;gt;&quot;
        );
        await サンプル.メッセージウィンドウ.消去する();

        while (1) {
            サンプル.現時刻 = Com.シリアル値を時分秒に変換する(Date.now());

            await サンプル.メッセージウィンドウ.表示する();
            await サンプル.メッセージウィンドウ.メッセージを表示する(
    &quot;暫くして、&amp;lt;var&amp;gt;サンプル.主人公名&amp;lt;/var&amp;gt;はまた何時なのか気になった&amp;lt;w&amp;gt;2&amp;lt;/w&amp;gt;&amp;lt;br&amp;gt;辺りの人に聞いてみると「&amp;lt;var&amp;gt;サンプル.現時刻&amp;lt;/var&amp;gt;」だと教えてくれた&amp;lt;w&amp;gt;&quot;
            );
            await サンプル.メッセージウィンドウ.消去する();
        }
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;1. クラスをインポート&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // 画像管理に関する機能を提供
import { スプライトクラス } from './sprite.js'; // スプライト（画像）管理に関する機能
import { レイヤークラス } from './layer.js'; // レイヤー（描画画面）管理
import { ループ } from './loop.js'; // 繰り返し処理管理
import { メッセージウィンドウクラス } from './messageWindow.js'; // メッセージ表示管理
import { Data } from './data.js'; // データ管理
import { Com } from './com.js'; // 共通処理管理
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;これらのインポートにより、各機能を効率的に使うことができます。例えば、画像管理やスプライト表示、ループ処理などのモジュールが含まれています。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;2. メイン処理&lt;/h3&gt;
&lt;p&gt;サンプル.main() は全体の流れを管理するメイン処理です。これにより以下の手順が実行されます：&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ループ処理を設定。&lt;/li&gt;
&lt;li&gt;メッセージウィンドウを作成。&lt;/li&gt;
&lt;li&gt;画像を読み込んでスプライトを作成。&lt;/li&gt;
&lt;li&gt;画面にスプライトやメッセージを表示。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;3. 画像を使用する流れ&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像読み込み処理：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 画像情報リスト = [
    { id: '町01', src: 'img/bg02.jpg' }, // 背景画像
    { id: '人物01', src: 'img/chara01.png' } // キャラクター画像
];
サンプル.画像管理 = new 画像管理クラス();
&lt;/code&gt;&lt;/pre&gt;
画像情報リストを定義し、それらを読み込みます。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スプライト作成処理：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;サンプル.背景01 = new スプライトクラス(サンプル.レイヤー, サンプル.画像管理.取得する('町01'), 0, 0, 640, 640);
サンプル.人物01 = new スプライトクラス(サンプル.レイヤー, サンプル.画像管理.取得する('人物01'), 0, 150, 640, 640);
&lt;/code&gt;&lt;/pre&gt;
背景やキャラクターなどをスプライトとして設定し、画面上に表示できるようにします。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;4. メッセージウィンドウの流れ&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;メッセージウィンドウを使ってテキストを表示します。例えば：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;プレイヤーは町を訪れた...&quot;);
&lt;/code&gt;&lt;/pre&gt;
このコードで、メッセージウィンドウにテキストを表示できます。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;5. 繰り返し処理&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;while (1) {
    サンプル.現時刻 = Com.シリアル値を時分秒に変換する(Date.now());
    await サンプル.メッセージウィンドウ.メッセージを表示する(&quot;現在時刻は&quot; + サンプル.現時刻);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;ここでは永遠ループを使って、時間の変化を表示しています。&lt;/p&gt;
&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907706&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907706&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907706&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;&lt;/div&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E3%83%A1%E3%83%83%E3%82%BB%E3%83%BC%E3%82%B8%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>移動しながらフェードイン／アウトする方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;前回までに画像を移動する方法とフェードイン、フェードアウトする方法を記したので、今度はそれらを合わせて、移動しながらフェードイン、フェードアウトする方法を記します。&lt;/p&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;670&quot; height=&quot;730&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample04/sample.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;01　ファイル構成&lt;/h2&gt;
&lt;p&gt;ファイルとそれを入れるフォルダーを以下のような構成します。&lt;br /&gt;
前回の「フェードイン／アウトする方法」と同じです。&lt;/p&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample04&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/sample.html&quot; target=&quot;_blank&quot;&gt;sample.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/js/layer.js&quot; target=&quot;_blank&quot;&gt;layer.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/js/loop.js&quot; target=&quot;_blank&quot;&gt;loop.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/img/bg01.jpg&quot; target=&quot;_blank&quot;&gt;bg01.jpg　※背景画像（720x720px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/img/chara01.png&quot; target=&quot;_blank&quot;&gt;chara01.png　※人物画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/img/mon01.png&quot; target=&quot;_blank&quot;&gt;mon01.png　※モンスター画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample04/img/mon02.png&quot; target=&quot;_blank&quot;&gt;mon02.png　※モンスター画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;02　ファイル全体の流れ&lt;/h2&gt;
&lt;p&gt;今回のコードは前回の「フェードイン／アウトする方法」に、移動しながらフェードインする処理と、移動しながらフェードアウトする処理を追加しています。&lt;/p&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;03　各部分の詳細解説&lt;/h2&gt;
&lt;p&gt;変更を行った「sample.js」と「sprite.js」のファイルについて解説していきます。&lt;/p&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;a.　sprite.js - スプライトクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class スプライトクラス {
    constructor(レイヤー, 画像要素, x1, y1, x2, y2) {
        this.レイヤー = レイヤー;
        this.ctx = レイヤー.ctx;
        this.画像要素 = 画像要素;
        this.座標を設定する(x1, y1, x2, y2);
    }

    座標を設定する(x1, y1, x2, y2) {
        const 画像要素 = this.画像要素;
        const 表示幅 = x2 - x1;
        const 表示高さ = y2 - y1;

        const 画像縦横比 = 画像要素.width / 画像要素.height;
        const 表示縦横比 = 表示幅 / 表示高さ;

        let 描画幅, 描画高さ, 位置調整x, 位置調整y;

        if (画像縦横比 &amp;gt; 表示縦横比) {
            描画幅 = 表示幅;
            描画高さ = 表示幅 / 画像縦横比;
            位置調整x = 0;
            位置調整y = (表示高さ - 描画高さ) / 2; // 垂直中央揃え
        } else {
            描画高さ = 表示高さ;
            描画幅 = 表示高さ * 画像縦横比;
            位置調整x = (表示幅 - 描画幅) / 2; // 水平中央揃え
            位置調整y = 0;
        }

        this.x = x1 + 位置調整x;
        this.y = y1 + 位置調整y;
        this.幅 = 描画幅;
        this.高さ = 描画高さ;
    }

    描画する() {
        this.ctx.drawImage(this.画像要素, this.x, this.y, this.幅, this.高さ); // 画像を描画
    }

    移動して描画する(移動幅x, 移動幅y, 停止位置x, 停止位置y) {
        const 制御情報 = { 状態フラグ: 1 }; // 状態フラグ = 1(移動フラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.移動する(制御情報, 移動幅x, 移動幅y, 停止位置x, 停止位置y);
                this.描画する();
                if (制御情報.状態フラグ) return;

                // 停止位置に来たら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }

    フェードインする(フェード時間 = 1) {
        const 増減値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        const 制御情報 = { 状態フラグ: 2, 不透明度: 0.0 }; // 状態フラグ = 2(フェードフラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.描画してフェードする(制御情報, 増減値);
                if (制御情報.状態フラグ) return;

                // 不透明度が100%になったら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }

    フェードアウトする(フェード時間 = 1) {
        const 増減値 = -1 / (60 * フェード時間); // フェード時間は秒単位とする
        const 制御情報 = { 状態フラグ: 2, 不透明度: 1.0 }; // 状態フラグ = 2(フェードフラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.描画してフェードする(制御情報, 増減値);
                if (制御情報.状態フラグ) return;

                // 不透明度が0%になったら描画処理を削除する
                this.レイヤー.処理を削除する(this);
                resolve();
            });
        })
    }

    移動してフェードインする(移動幅x, 移動幅y, 停止位置x, 停止位置y, フェード時間 = 1) {
        const 増減値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        const 制御情報 = { 状態フラグ: 3, 不透明度: 0.0 }; // 状態フラグ = 1(移動フラグオン) + 2(フェードフラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.移動する(制御情報, 移動幅x, 移動幅y, 停止位置x, 停止位置y);
                this.描画してフェードする(制御情報, 増減値);
                if (制御情報.状態フラグ) return;

                // 停止位置に来て、尚かつ不透明度が100%なったら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }

    移動してフェードアウトする(移動幅x, 移動幅y, 停止位置x, 停止位置y, フェード時間 = 1) {
        const 増減値 = -1 / (60 * フェード時間); // フェード時間は秒単位とする
        const 制御情報 = { 状態フラグ: 3, 不透明度: 1.0 }; // 状態フラグ = 1(移動フラグオン) + 2(フェードフラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.移動する(制御情報, 移動幅x, 移動幅y, 停止位置x, 停止位置y);
                this.描画してフェードする(制御情報, 増減値);
                if (制御情報.状態フラグ) return;

                // 停止位置に来て、尚かつ不透明度が0%なったら描画処理を削除する
                this.レイヤー.処理を削除する(this);
                resolve();
            });
        })
    }

    移動する(制御情報, 移動幅x, 移動幅y, 停止位置x, 停止位置y) {
        if ((制御情報.状態フラグ &amp;amp; 1) ^ 1) return; // 移動フラグがオフなら移動しない

        if (移動幅x) {
            this.x += 移動幅x;
            if (移動幅x &amp;gt; 0) {
                if (this.x &amp;gt;= 停止位置x) 制御情報.状態フラグ &amp;amp;= ~1; // 移動フラグをオフにする
            } else {
                if (this.x &amp;lt;= 停止位置x) 制御情報.状態フラグ &amp;amp;= ~1; // 移動フラグをオフにする
            }
        }
        if (移動幅y) {
            this.y += 移動幅y;
            if (移動幅y &amp;gt; 0) {
                if (this.y &amp;gt;= 停止位置y) 制御情報.状態フラグ &amp;amp;= ~1; // 移動フラグをオフにする
            } else {
                if (this.y &amp;lt;= 停止位置y) 制御情報.状態フラグ &amp;amp;= ~1; // 移動フラグをオフにする
            }
        }
    }

    描画してフェードする(制御情報, 増減値) {
        this.ctx.save(); // 現在の描画状態を保存
        this.ctx.globalAlpha = 制御情報.不透明度;
        this.描画する();
        this.ctx.restore(); // 元の描画状態を復元

        if ((制御情報.状態フラグ &amp;amp; 2) ^ 2) return; // フェードフラグがオフならフェードしない

        制御情報.不透明度 += 増減値;
        if (制御情報.不透明度 &amp;gt; 0 &amp;amp;&amp;amp; 制御情報.不透明度 &amp;lt; 1) return;

        // 不透明度が下限値または上限値を超えたら、フェードフラグをオフにする
        制御情報.状態フラグ &amp;amp;= ~2;

        // 不透明度が下限値と上限値を超えないようにする
        制御情報.不透明度 = Math.max(0, Math.min(1, 制御情報.不透明度));
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;移動しながらフェードイン&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;    移動してフェードインする(移動幅x, 移動幅y, 停止位置x, 停止位置y, フェード時間 = 1) {
        const 増減値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        const 制御情報 = { 状態フラグ: 3, 不透明度: 0.0 }; // 状態フラグ = 1(移動フラグオン) + 2(フェードフラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.移動する(制御情報, 移動幅x, 移動幅y, 停止位置x, 停止位置y);
                this.描画してフェードする(制御情報, 増減値);
                if (制御情報.状態フラグ) return;

                // 停止位置に来て、尚かつ不透明度が100%なったら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;移動処理（移動する）と透明度変更処理（描画してフェードインする）を同時に行います。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;移動しながらフェードアウト&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;    移動してフェードアウトする(移動幅x, 移動幅y, 停止位置x, 停止位置y, フェード時間 = 1) {
        const 増減値 = -1 / (60 * フェード時間); // フェード時間は秒単位とする
        const 制御情報 = { 状態フラグ: 3, 不透明度: 1.0 }; // 状態フラグ = 1(移動フラグオン) + 2(フェードフラグオン)
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.移動する(制御情報, 移動幅x, 移動幅y, 停止位置x, 停止位置y);
                this.描画してフェードする(制御情報, 増減値);
                if (制御情報.状態フラグ) return;

                // 停止位置に来て、尚かつ不透明度が0%なったら描画処理を削除する
                this.レイヤー.処理を削除する(this);
                resolve();
            });
        })
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;移動処理（移動する）と透明度変更処理（描画してフェードアウトする）を同時に行います。&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;状態管理 (フラグの活用)&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;このコードでは「状態フラグ」を使ってスプライトの状態を管理しています。&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 制御情報 = { 状態フラグ: 3, 不透明度: 0.0 };
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;状態フラグ：&lt;/span&gt;スプライトが「移動中」か「フェード中」かを判定します。
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;0:処理完了&lt;/li&gt;
&lt;li&gt;1:移動中（移動フラグ）&lt;/li&gt;
&lt;li&gt;2:フェード中（フェードフラグ）&lt;/li&gt;
&lt;li&gt;3:移動中＋フェード中&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;移動処理が完了すると状態フラグの移動フラグ（1）をオフにします。&lt;/li&gt;
&lt;li&gt;透明度変更処理が完了すると状態フラグのフェードフラグ（2）をオフにします。&lt;/li&gt;
&lt;li&gt;移動処理と透明度変更処理の両方が完了すると状態フラグは処理完了（0）になります。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;b.　sample.js - サンプルクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { スプライトクラス } from './sprite.js'; // クラスをインポート
import { レイヤークラス } from './layer.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート

class サンプル {
    static async main() {
        const レイヤー = new レイヤークラス('canvas.レイヤー1');
        const 画像管理 = new 画像管理クラス();
        ループ.初期化する(1000/60);
        ループ.開始する();

        // 事前に読み込む画像の配列
        const 画像情報リスト = [
            { id: '草原', src: 'img/bg01.jpg' },
            { id: '人物01', src: 'img/chara01.png' },
            { id: '炎竜', src: 'img/mon01.png' },
            { id: 'デビル', src: 'img/mon02.png' }
        ];

        // ページ初期化時に画像をプリロード
        if (!await 画像管理.画像を読み込む(画像情報リスト)) return;

        // 画像の描画位置を設定
        const 背景01 = new スプライトクラス(レイヤー, 画像管理.取得する('草原'), 0, 0, 640, 640);

        const 人物01 = new スプライトクラス(レイヤー, 画像管理.取得する('人物01'), 0, 100, 640, 640);
        const 人物01正位置 = { x: 人物01.x, y: 人物01.y };
        人物01.座標を設定する(640, 100, 1280, 640); //初期表示位置を設定する

        const モンスター01 = new スプライトクラス(レイヤー, 画像管理.取得する('炎竜'), 0, 0, 640, 540);
        const モンスター01正位置 = { x: モンスター01.x, y: モンスター01.y };
        モンスター01.座標を設定する(-640, 0, 0, 540); //初期表示位置を設定する

        const モンスター02 = new スプライトクラス(レイヤー, 画像管理.取得する('デビル'), 0, 320, 320, 640);
        const モンスター02正位置 = { x: モンスター02.x, y: モンスター02.y };
        モンスター02.座標を設定する(640, -640, 960, 320); //初期表示位置を設定する

        const モンスター03 = new スプライトクラス(レイヤー, 画像管理.取得する('デビル'), 320, 320, 640, 640);

        ループ.処理を追加する(レイヤー, レイヤー.描画する.bind(レイヤー));
        背景01.レイヤー.処理を追加する(背景01, 背景01.描画する.bind(背景01));

        let プロミスリスト;
        while (1) {
            await 人物01.移動してフェードインする(-10, 0, 人物01正位置.x, 0, 1);
            await サンプル.一時停止(2000);

            プロミスリスト = [];
            プロミスリスト.push(人物01.移動してフェードアウトする(5, 0, 640, 0, 0.5));
            プロミスリスト.push(モンスター01.移動して描画する(5, 0, モンスター01正位置.x, 0));
            プロミスリスト.push(モンスター02.移動してフェードインする(-10, 10, モンスター02正位置.x, モンスター02正位置.y, 1.5));
            プロミスリスト.push(モンスター03.フェードインする(0.5));
            await Promise.all(プロミスリスト);
            await サンプル.一時停止(2000);

            プロミスリスト = [];
            プロミスリスト.push(モンスター01.移動して描画する(0, 10, 0, 640));
            プロミスリスト.push(モンスター02.移動してフェードアウトする(0, 5, 0, 640,0.5));
            プロミスリスト.push(モンスター03.フェードアウトする(3));
            await Promise.all(プロミスリスト);
            await サンプル.一時停止(2000);

            モンスター01.座標を設定する(-640, 0, 0, 540); //初期表示位置を設定する
            モンスター02.座標を設定する(640, -640, 960, 320); //初期表示位置を設定する
        }
    }

    static 一時停止(時間) {
        return new Promise(resolve =&amp;gt; setTimeout(resolve, 時間));
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;このコードの全体の流れ&lt;/span&gt;&lt;/h4&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像を読み込む:&lt;/span&gt;&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;必要な画像を事前にメモリへロードします（画像管理クラスを使用）。&lt;/li&gt;
&lt;li&gt;ロード後に各画像をスプライトクラスとして設定し、描画を準備します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;アニメーションの管理:&lt;/span&gt;&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;ループを使って、画面内の描画やアニメーション（フェードイン/アウト）を繰り返します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動しながらフェード処理を実行:&lt;/span&gt;&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;人物 や モンスター 画像を移動しながらフェードインまたはフェードアウトさせ、アニメーションを構成します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一時停止（待機）:&lt;/span&gt;&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;指定時間だけ処理を止めることで、画面切り替えのタイミングを調整します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;主要なポイントの解説&lt;/span&gt;&lt;/h4&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動しながらフェードイン処理：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;人物01.移動してフェードインする(-10, 0, 人物01正位置.x, 0, 1);
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動速度：&lt;/span&gt;上記の例では、1フレームごとに10ピクセル左に移動します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェードイン：&lt;/span&gt;上記の例では、1秒以内に透明度が上がり（0&amp;rArr;1）、完全に表示されます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動しながらフェードアウト処理：&lt;/span&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;人物01.移動してフェードアウトする(5, 0, 640, 0, 0.5);
&lt;/code&gt;&lt;/pre&gt;
&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動速度：&lt;/span&gt;上記の例では、1フレームごとに5ピクセル右に移動します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェードイン：&lt;/span&gt;上記の例では、0.5秒以内に透明度が下がり（1&amp;rArr;0）、完全に非表示になります。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907703&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907703&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907703&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E7%A7%BB%E5%8B%95%E3%81%97%E3%81%AA%E3%81%8C%E3%82%89%E3%83%95%E3%82%A7%E3%83%BC%E3%83%89%E3%82%A4%E3%83%B3%EF%BC%8F%E3%82%A2%E3%82%A6%E3%83%88%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>フェードイン／アウトする方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;今回は画像をフェードイン、フェードアウトする方法を記します。&lt;/p&gt;
&lt;p class=&quot;bold&quot;&gt;フェードインとフェードアウトとは？&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェードイン:&lt;/span&gt; 画像やオブジェクトが徐々に現れ、不透明になる効果のこと。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェードアウト:&lt;/span&gt; 画像やオブジェクトが徐々に透明になり、消えるような効果のこと。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;この2つは、滑らかなトランジションを表現するために、ゲームやアニメーション、スライドショーなどでよく使われます。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;670&quot; height=&quot;730&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample03/sample.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;01　ファイル構成&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;ファイルとそれを入れるフォルダーを以下のような構成します。&lt;br /&gt;
前回の「画像を移動する方法」と同じです。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample03&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample03/sample.html&quot; target=&quot;_blank&quot;&gt;sample.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample03/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample03/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample03/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample03/js/layer.js&quot; target=&quot;_blank&quot;&gt;layer.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample03/js/loop.js&quot; target=&quot;_blank&quot;&gt;loop.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/bg01.jpg&quot; target=&quot;_blank&quot;&gt;bg01.jpg　※背景画像（720x720px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/chara01.png&quot; target=&quot;_blank&quot;&gt;chara01.png　※人物画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/mon01.png&quot; target=&quot;_blank&quot;&gt;mon01.png　※モンスター画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/mon02.png&quot; target=&quot;_blank&quot;&gt;mon02.png　※モンスター画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;02　ファイル全体の流れ&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;今回のコードは全体的に前回の「画像を移動する方法」と同じです。&lt;br /&gt;
そのため、変更を行ったフェードイン、フェードアウトの処理について記したいと思います。&lt;/p&gt;
&lt;p class=&quot;bold&quot;&gt;どのように動くのか：&lt;/p&gt;
&lt;p&gt;フェードの効果を実現するには、不透明度（透明度の逆）を段階的に変化させる必要があります。&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;不透明度（Alpha値） は 1.0 で完全に見える状態を表します。&lt;/li&gt;
&lt;li&gt;0.0 は完全に透明な状態を表します。&lt;/li&gt;
&lt;li&gt;フェードアウトでは、1.0 &amp;rarr; 0.0 へ徐々に値を下げます。&lt;/li&gt;
&lt;li&gt;フェードインでは、0.0 &amp;rarr; 1.0 へ徐々に値を上げます。&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;03　各部分の詳細解説&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;変更を行った「sample.js」と「sprite.js」のファイルについて解説していきます。&lt;/p&gt;
&lt;/div&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;a.　sprite.js - スプライトクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class スプライトクラス {
    constructor(レイヤー, 画像要素, x1, y1, x2, y2) {
        this.レイヤー = レイヤー;
        this.ctx = レイヤー.ctx;
        this.画像要素 = 画像要素;
        this.座標を設定する(x1, y1, x2, y2);
    }

    座標を設定する(x1, y1, x2, y2) {
        const 画像要素 = this.画像要素;
        const 表示幅 = x2 - x1;
        const 表示高さ = y2 - y1;

        const 画像縦横比 = 画像要素.width / 画像要素.height;
        const 表示縦横比 = 表示幅 / 表示高さ;

        let 描画幅, 描画高さ, 位置調整x, 位置調整y;

        if (画像縦横比 &amp;gt; 表示縦横比) {
            描画幅 = 表示幅;
            描画高さ = 表示幅 / 画像縦横比;
            位置調整x = 0;
            位置調整y = (表示高さ - 描画高さ) / 2; // 垂直中央揃え
        } else {
            描画高さ = 表示高さ;
            描画幅 = 表示高さ * 画像縦横比;
            位置調整x = (表示幅 - 描画幅) / 2; // 水平中央揃え
            位置調整y = 0;
        }

        this.x = x1 + 位置調整x;
        this.y = y1 + 位置調整y;
        this.幅 = 描画幅;
        this.高さ = 描画高さ;
    }

    描画する() {
        this.ctx.drawImage(this.画像要素, this.x, this.y, this.幅, this.高さ); // 画像を描画
    }

    移動して描画する(移動幅x, 移動幅y, 停止位置x, 停止位置y) {
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                if (移動幅x) this.x += 移動幅x;
                if (移動幅y) this.y += 移動幅y;
                this.描画する();

                let 停止フラグ = false;
                if (移動幅x) {
                    if (移動幅x &amp;gt; 0) {
                        if (this.x &amp;gt;= 停止位置x) 停止フラグ = true;
                    } else if (移動幅x &amp;lt; 0) {
                        if (this.x &amp;lt;= 停止位置x) 停止フラグ = true;
                    }
                }
                if (移動幅y) {
                    if (移動幅y &amp;gt; 0) {
                        if (this.y &amp;gt;= 停止位置y) 停止フラグ = true;
                    } else if (移動幅y &amp;lt; 0) {
                        if (this.y &amp;lt;= 停止位置y) 停止フラグ = true;
                    }
                }
                if (!停止フラグ) return;

                // 停止位置に来たら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }

    フェードアウトする(フェード時間 = 1) {
        const 減少値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        let 不透明度 = 1.0;
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.ctx.save(); // 現在の描画状態を保存
                this.ctx.globalAlpha = 不透明度;
                this.描画する();
                this.ctx.restore(); // 元の描画状態を復元
                不透明度 -= 減少値;
                if (不透明度 &amp;gt; 0) return;

                // 不透明度が0%になったら描画処理を削除する
                this.レイヤー.処理を削除する(this);
                resolve();
            });
        })
    }

    フェードインする(フェード時間 = 1) {
        const 増加値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        let 不透明度 = 0.0;
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.ctx.save(); // 現在の描画状態を保存
                this.ctx.globalAlpha = 不透明度;
                this.描画する();
                this.ctx.restore(); // 元の描画状態を復元
                不透明度 += 増加値;
                if (不透明度 &amp;lt; 1) return;

                // 不透明度が100%になったら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;追加したコードについて&lt;/span&gt;&lt;/h4&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p class=&quot;bold&quot;&gt;フェードアウト：&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;    フェードアウトする(フェード時間 = 1) {
        const 減少値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        let 不透明度 = 1.0;
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.ctx.save(); // 現在の描画状態を保存
                this.ctx.globalAlpha = 不透明度;
                this.描画する();
                this.ctx.restore(); // 元の描画状態を復元
                不透明度 -= 減少値;
                if (不透明度 &amp;gt; 0) return;

                // 不透明度が0%になったら描画処理を削除する
                this.レイヤー.処理を削除する(this);
                resolve();
            });
        })
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;処理の流れ:&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;最初は画像が完全に表示されています（不透明度 = 1.0）。&lt;/li&gt;
&lt;li&gt;徐々に 不透明度 を減少（1フレームごとに少しずつ）させます。&lt;/li&gt;
&lt;li&gt;完全に透明になったら処理を終了します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント:&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ctx.globalAlpha を使って、描画時の透明度を設定しています。&lt;/li&gt;
&lt;li&gt;this.ctx.save() と this.ctx.restore() を使用することで、他の描画操作に影響が出ないようにしています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p class=&quot;bold&quot;&gt;フェードイン：&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;    フェードインする(フェード時間 = 1) {
        const 増加値 = 1 / (60 * フェード時間); // フェード時間は秒単位とする
        let 不透明度 = 0.0;
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                this.ctx.save(); // 現在の描画状態を保存
                this.ctx.globalAlpha = 不透明度;
                this.描画する();
                this.ctx.restore(); // 元の描画状態を復元
                不透明度 += 増加値;
                if (不透明度 &amp;lt; 1) return;

                // 不透明度が100%になったら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;処理の流れ：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;最初は画像が完全に透明な状態から始まります（不透明度 = 0.0）。&lt;/li&gt;
&lt;li&gt;徐々に 不透明度 を増加させ、見える状態にしていきます。&lt;/li&gt;
&lt;li&gt;不透明度が 1.0 になったら処理を終了します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;フェードアウトと同様に、ctx.globalAlpha を使用して不透明度を段階的に変更しています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;初心者向けのポイント&lt;/span&gt;&lt;/h4&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;不透明度は時間でコントロール：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;フェード効果は、「何秒以内に透明度を変える」といった具合に、秒で指定できるようにしています（小数点も可）。&lt;/li&gt;
&lt;li&gt;1フレーム（このコードでは、約1/60秒）ごとに透明度を少しずつ調整しています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;非同期処理：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;フェード効果を非同期で行う仕組み（Promise）を使うことで、他の処理と平行して行えるようになっています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;b.　sample.js - サンプルクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { スプライトクラス } from './sprite.js'; // クラスをインポート
import { レイヤークラス } from './layer.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート

class サンプル {
    static async main() {
        const レイヤー = new レイヤークラス('canvas.レイヤー1');
        const 画像管理 = new 画像管理クラス();
        ループ.初期化する(1000/60);
        ループ.開始する();

        // 事前に読み込む画像の配列
        const 画像情報リスト = [
            { id: '草原', src: 'img/bg01.jpg' },
            { id: '人物01', src: 'img/chara01.png' },
            { id: '炎竜', src: 'img/mon01.png' },
            { id: 'デビル', src: 'img/mon02.png' }
        ];

        // ページ初期化時に画像をプリロード
        if (!await 画像管理.画像を読み込む(画像情報リスト)) return;

        // 画像の描画位置を設定
        const 背景01 = new スプライトクラス(レイヤー, 画像管理.取得する('草原'), 0, 0, 640, 640);
        const 人物01 = new スプライトクラス(レイヤー, 画像管理.取得する('人物01'), 0, 100, 640, 640);
        const モンスター01 = new スプライトクラス(レイヤー, 画像管理.取得する('炎竜'), 0, 0, 640, 540);
        const モンスター02 = new スプライトクラス(レイヤー, 画像管理.取得する('デビル'), 0, 320, 320, 640);
        const モンスター03 = new スプライトクラス(レイヤー, 画像管理.取得する('デビル'), 320, 320, 640, 640);

        ループ.処理を追加する(レイヤー, レイヤー.描画する.bind(レイヤー));
        背景01.レイヤー.処理を追加する(背景01, 背景01.描画する.bind(背景01));

        let プロミスリスト;
        while (1) {
            await 人物01.フェードインする();
            await サンプル.一時停止(2000);

            プロミスリスト = [];
            プロミスリスト.push(人物01.フェードアウトする(2.5));
            プロミスリスト.push(モンスター01.フェードインする(4));
            プロミスリスト.push(モンスター02.フェードインする(3));
            プロミスリスト.push(モンスター03.フェードインする(1.5));
            await Promise.all(プロミスリスト);
            await サンプル.一時停止(2000);

            await モンスター02.フェードアウトする();
            await サンプル.一時停止(2000);

            プロミスリスト = [];
            プロミスリスト.push(モンスター01.フェードアウトする(1.5));
            プロミスリスト.push(モンスター03.フェードアウトする(3));
            await Promise.all(プロミスリスト);
            await サンプル.一時停止(2000);
        }
    }

    static 一時停止(時間) {
        return new Promise(resolve =&amp;gt; setTimeout(resolve, 時間));
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;このコードの全体の流れ&lt;/span&gt;&lt;/h4&gt;
&lt;div class=&quot;本文&quot;&gt;&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像を読み込む：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;必要な画像を事前にメモリへロードします（画像管理クラスを使用）。&lt;/li&gt;
&lt;li&gt;ロード後に各画像をスプライトクラスとして設定し、描画を準備します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;アニメーションの管理：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;ループを使って、画面内の描画やアニメーション（フェードイン/アウト）を繰り返します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェード処理を実行：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;人物 や モンスター 画像をフェードインまたはフェードアウトさせ、アニメーションを構成します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一時停止（待機）：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;指定時間だけ処理を止めることで、画面切り替えのタイミングを調整します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;主要なポイントの解説&lt;/span&gt;&lt;/h4&gt;
&lt;div class=&quot;本文&quot;&gt;&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像のプリロード：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;画面をスムーズに表示するため、使用する画像を事前に読み込みます。
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 画像情報リスト = [
    { id: '草原', src: 'img/bg01.jpg' },
    { id: '人物01', src: 'img/chara01.png' },
    { id: '炎竜', src: 'img/mon01.png' },
    { id: 'デビル', src: 'img/mon02.png' }
];
await 画像管理.画像を読み込む(画像情報リスト);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;src は画像ファイルのパス、id はその画像を区別するための名前です。&lt;/li&gt;
&lt;li&gt;この処理が完了するまで次の処理には進みません（await の利用）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像の描画と配置：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;画像の表示サイズや位置を設定します。
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 背景01 = new スプライトクラス(レイヤー, 画像管理.取得する('草原'), 0, 0, 640, 640);
const 人物01 = new スプライトクラス(レイヤー, 画像管理.取得する('人物01'), 0, 100, 640, 640);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;スプライトクラス は画像をキャンバス上に描画するためのクラスです。&lt;/li&gt;
&lt;li&gt;x1, y1, x2, y2 は画像を配置する位置とサイズを指定しています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;フェード処理：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;画像の表示サイズや位置を設定します。
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;await 人物01.フェードインする();
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;await を使うことで、フェードインが完全に終わるまで待機します。&lt;/li&gt;
&lt;li&gt;フェードアウトも同様の構文で実現できます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;同時処理の実行：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;複数の画像が同時にフェードするアニメーションを作ります。
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;プロミスリスト = [];
プロミスリスト.push(人物01.フェードアウトする(2.5));
プロミスリスト.push(モンスター01.フェードインする(4));
プロミスリスト.push(モンスター02.フェードインする(3));
プロミスリスト.push(モンスター03.フェードインする(1.5));
await Promise.all(プロミスリスト);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;Promise.all を使うことで、すべてのフェード処理を並行して実行します。&lt;/li&gt;
&lt;li&gt;フェードの時間はそれぞれ異なります（例: 2.5秒 や 4秒）。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一時停止：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;目的：&lt;/span&gt;動作の切り替わりが分かるように、少しだけ一時停止しています。
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;await サンプル.一時停止(2000);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;ポイント：&lt;/span&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;単純に指定したミリ秒（2000ミリ秒 = 2秒）待機するだけの処理です。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907702&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907702&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907702&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;&lt;/div&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E3%83%95%E3%82%A7%E3%83%BC%E3%83%89%E3%82%A4%E3%83%B3%EF%BC%8F%E3%82%A2%E3%82%A6%E3%83%88%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>画像を移動する方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;次は画像を移動する方法を記します。&lt;/li&gt;
&lt;li&gt;人物やモンスターの画像を上下左右斜め方向に移動して描画しています。&lt;/li&gt;
&lt;li&gt;前回の「画像を表示する方法」を元に、少し変更を加えています。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;670&quot; height=&quot;730&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample02/sample.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;01　ファイル構成&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;それでは処理を見ていきます。&lt;br /&gt;
先ずはファイル構成です。&lt;br /&gt;
ファイルとそれを入れるフォルダーを以下のような構成します。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample02&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/sample.html&quot; target=&quot;_blank&quot;&gt;sample.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/js/layer.js&quot; target=&quot;_blank&quot;&gt;layer.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/js/loop.js&quot; target=&quot;_blank&quot;&gt;loop.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/bg01.jpg&quot; target=&quot;_blank&quot;&gt;bg01.jpg　※背景画像（720x720px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/chara01.png&quot; target=&quot;_blank&quot;&gt;chara01.png　※人物画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/mon01.png&quot; target=&quot;_blank&quot;&gt;mon01.png　※モンスター画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample02/img/mon02.png&quot; target=&quot;_blank&quot;&gt;mon02.png　※モンスター画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;02　ファイル全体の流れ&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;コード全体で行おうとしていることは以下の通りです。&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;HTMLファイルに埋め込まれた &amp;lt;canvas&amp;gt; 要素に対して、JavaScriptを使って画像を描画します。&lt;/li&gt;
&lt;li&gt;画像管理クラス を使って画像をあらかじめ読み込みます（プリロード処理）。&lt;/li&gt;
&lt;li&gt;読み込んだ画像を スプライトクラス を使って座標を移動して描画します。&lt;/li&gt;
&lt;li&gt;レイヤークラス は &amp;lt;canvas&amp;gt; 要素をクリアしてから スプライトクラス の描画処理を実行します。&lt;/li&gt;
&lt;li&gt;ループクラス はフレームレートのタイミングで レイヤークラス の描画処理を繰り返し実行します。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;これにより、スプライトクラス の描画処理が繰り返し実行され、移動し続ける画像を表示できるようになります。&lt;/p&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;03　各部分の詳細解説&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;次は各ファイル毎に解説していきます。&lt;br /&gt;
尚、「imageManager.js」については、前回の「画像を表示する方法」から変更がないので割愛します。&lt;/p&gt;
&lt;/div&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;a.　sample.html - HTMLファイル&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang=&quot;ja&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=660,user-scalable=no,shrink-to-fit=yes&quot;&amp;gt;
    &amp;lt;title&amp;gt;画像を移動する方法&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;style&amp;gt;
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }
    
        canvas {
            display: block;
            margin: 20px auto;
            border: 1px solid #ccc;
        }
    
        p {
            font-size: 18px;
            color: #333;
        }
    &amp;lt;/style&amp;gt;
    
    &amp;lt;p&amp;gt;
        リフレッシュレート：&amp;lt;span class=&quot;リフレッシュレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;Hz
        ／フレームレート：&amp;lt;span class=&quot;フレームレート&quot;&amp;gt;0&amp;lt;/span&amp;gt;fps
    &amp;lt;/p&amp;gt;
    &amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
    &amp;lt;script type=&quot;module&quot; src=&quot;js/sample.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;このファイルでは、以下のことを行っています。&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;リフレッシュレートとフレームレートの表示：&lt;/span&gt;ウェブページに描画処理のパフォーマンス（Hzやfps）を表示するためのテキスト。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;キャンバスの作成：&lt;/span&gt;&amp;lt;canvas&amp;gt;タグを使って、図形や画像を描画する領域を作成しています。ここでは、幅640px、高さ640pxのキャンバスを作っています。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;JavaScriptの読み込み：&lt;/span&gt;&amp;lt;script type=&quot;module&quot; src=&quot;js/sample.js&quot;&amp;gt;&amp;lt;/script&amp;gt;で外部のJavaScriptコード（sample.js）を読み込んでいます。&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;bold&quot;&gt;初心者向けのポイント：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;キャンバスは画面上に見える「お絵かきエリア」みたいなものです。&lt;/li&gt;
&lt;li&gt;JavaScriptを使うことで、動的に画像を描画したり、動かしたりできます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;b.　layer.js - レイヤークラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class レイヤークラス {
    constructor(セレクター) {
        this.canvas = document.querySelector(セレクター);
        this.ctx = this.canvas.getContext('2d');
        this.処理リスト = [];
    }

    描画する() {
        this.クリアする();

        // ループ中に処理リストの処理が削除されてもいいように逆順でループします
        for (let i = this.処理リスト.length - 1; i &amp;gt;= 0; i--) {
            this.処理リスト[i].処理();
        }
    }

    クリアする() {
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
    }

    処理を追加する(id, 処理) {
        const 既存処理 = this.処理リスト.find(x =&amp;gt; x.id == id);
        if (既存処理) {
            既存処理.処理 = 処理; // 既にある場合は差し替える
            return;
        }

        this.処理リスト.unshift({ id, 処理 });
    }

    処理を削除する(id) {
        this.処理リスト = this.処理リスト.filter(x =&amp;gt; x.id != id);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;レイヤークラスは、Canvas要素（キャンバス）で画像や図形を描画するための管理クラスです。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p class=&quot;bold&quot;&gt;主な機能：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;キャンバスの初期化：&lt;/span&gt;指定されたセレクター（例: .レイヤー1）からキャンバス要素を取得し、2D描画コンテキスト（ctx）を準備します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;描画処理：&lt;/span&gt;登録された処理（処理リスト）を順番に実行して、キャンバスに描画します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;キャンバスをクリアする：&lt;/span&gt;クリアするメソッドでキャンバスの中身を消去します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const レイヤー = new レイヤークラス('.レイヤー1'); 
// 上記はキャンバス（.レイヤー1）を管理する新しいレイヤーを作成します。
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;c.　sprite.js - スプライトクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class スプライトクラス {
    constructor(レイヤー, 画像要素, x1, y1, x2, y2) {
        this.レイヤー = レイヤー;
        this.ctx = レイヤー.ctx;
        this.画像要素 = 画像要素;
        this.レイヤー.処理を追加する(this, this.描画する.bind(this));
        this.座標を設定する(x1, y1, x2, y2);
    }

    座標を設定する(x1, y1, x2, y2) {
        const 画像要素 = this.画像要素;
        const 表示幅 = x2 - x1;
        const 表示高さ = y2 - y1;

        const 画像縦横比 = 画像要素.width / 画像要素.height;
        const 表示縦横比 = 表示幅 / 表示高さ;

        let 描画幅, 描画高さ, 位置調整X, 位置調整Y;

        if (画像縦横比 &amp;gt; 表示縦横比) {
            描画幅 = 表示幅;
            描画高さ = 表示幅 / 画像縦横比;
            位置調整X = 0;
            位置調整Y = (表示高さ - 描画高さ) / 2; // 垂直中央揃え
        } else {
            描画高さ = 表示高さ;
            描画幅 = 表示高さ * 画像縦横比;
            位置調整X = (表示幅 - 描画幅) / 2; // 水平中央揃え
            位置調整Y = 0;
        }

        this.x = x1 + 位置調整X;
        this.y = y1 + 位置調整Y;
        this.幅 = 描画幅;
        this.高さ = 描画高さ;
    }

    描画する() {
        this.ctx.drawImage(this.画像要素, this.x, this.y, this.幅, this.高さ); // 画像を描画
    }

    移動して描画する(移動幅x, 移動幅y, 停止位置x, 停止位置y) {
        return new Promise(resolve =&amp;gt; {
            this.レイヤー.処理を追加する(this, () =&amp;gt; {
                if (移動幅x) this.x += 移動幅x;
                if (移動幅y) this.y += 移動幅y;
                this.描画する();

                let 停止フラグ = false;
                if (移動幅x) {
                    if (移動幅x &amp;gt; 0) {
                        if (this.x &amp;gt;= 停止位置x) 停止フラグ = true;
                    } else if (移動幅x &amp;lt; 0) {
                        if (this.x &amp;lt;= 停止位置x) 停止フラグ = true;
                    }
                }
                if (移動幅y) {
                    if (移動幅y &amp;gt; 0) {
                        if (this.y &amp;gt;= 停止位置y) 停止フラグ = true;
                    } else if (移動幅y &amp;lt; 0) {
                        if (this.y &amp;lt;= 停止位置y) 停止フラグ = true;
                    }
                }
                if (!停止フラグ) return;

                // 停止位置に来たら描画だけの処理に切替える
                this.レイヤー.処理を追加する(this, this.描画する.bind(this));
                resolve();
            });
        })
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;スプライトクラスは、画面上の画像（スプライト）を管理するためのクラスです。たとえば、キャラクターや背景画像を表示したり動かしたりする処理を提供します。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p class=&quot;bold&quot;&gt;主な機能：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;座標を設定：&lt;/span&gt;画像の位置（x, y）やサイズ（幅、高さ）を設定します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;描画：&lt;/span&gt;キャンバス上に画像を描画します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;移動アニメーション：&lt;/span&gt;指定した速さや方向に画像を移動しながら描画します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 人物01 = new スプライトクラス(レイヤー, 画像, x1, y1, x2, y2);
// 人物01というスプライトを作成し、レイヤー上に表示します。
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;d.　loop.js - ループクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class ループ {
    static 初期化する(フレームレート) {
        ループ.処理リスト = [];
        ループ.リフレッシュ時刻;
        ループ.処理時刻;
        ループ.リフレッシュカウンタ = 0;
        ループ.処理カウンタ = 0;
        ループ.フレームレート = フレームレート | 1000 / 60;
        ループ.リフレッシュレート要素 = document.querySelector(&quot;.リフレッシュレート&quot;);
        ループ.フレームレート要素 = document.querySelector(&quot;.フレームレート&quot;);
    }

    static 開始する() {
        ループ.処理時刻 = ループ.リフレッシュ時刻 = Date.now();
        ループ.する();
    }

    static する() {
        ループ.処理を実行する();
        requestAnimationFrame(ループ.する);
    }

    static 処理を実行する() {
        const 現時刻 = Date.now();
        if (現時刻 - ループ.リフレッシュ時刻 &amp;lt; 1000) {
            ループ.リフレッシュカウンタ++;
        } else {
            ループ.リフレッシュ時刻 = 現時刻;
            ループ.リフレッシュレート要素.innerHTML = ループ.リフレッシュカウンタ;
            ループ.フレームレート要素.innerHTML = ループ.処理カウンタ;
            ループ.リフレッシュカウンタ = 0;
            ループ.処理カウンタ = 0;
        }

        if (現時刻 - ループ.処理時刻 &amp;lt; ループ.フレームレート) return;
        ループ.処理時刻 += ループ.フレームレート;
        ループ.処理カウンタ++;

        // ループ中に処理リストの処理が削除されてもいいように逆順でループします
        for (let i = ループ.処理リスト.length - 1; i &amp;gt;= 0; i--) {
            ループ.処理リスト[i].処理();
        }
    }

    static 処理を追加する(id, 処理) {
        const 既存処理 = ループ.処理リスト.find(x =&amp;gt; x.id == id);
        if (既存処理) {
            既存処理.処理 = 処理; // 既にある場合は差し替える
            return;
        }

        ループ.処理リスト.push({ id, 処理 });
    }

    static 処理を削除する(id) {
        ループ.処理リスト = ループ.処理リスト.filter(x =&amp;gt; x.id != id);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;ループクラスは、アニメーションを管理するためのメインループを提供します。アニメーションとは、画像を動かしたり、複数の処理を一定の時間間隔で繰り返すことを指します。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p class=&quot;bold&quot;&gt;主な機能：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;処理を管理：&lt;/span&gt;アニメーションに必要な複数の処理をリストとして登録し、順番に実行します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一定のフレームレートで実行：&lt;/span&gt;滑らかな動きを実現するために、1秒間に60回（または指定のレート）処理を呼び出します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;ループ.初期化する();
ループ.開始する();
ループ.処理を追加する(レイヤー, レイヤー.描画する.bind(レイヤー));
// アニメーションを開始し、レイヤーの描画をループ内で実行します。
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;e.　sample.js - サンプルクラス&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { スプライトクラス } from './sprite.js'; // クラスをインポート
import { レイヤークラス } from './layer.js'; // クラスをインポート
import { ループ } from './loop.js'; // クラスをインポート

class サンプル {
    static async main() {
        const レイヤー = new レイヤークラス('canvas.レイヤー1');
        const 画像管理 = new 画像管理クラス();
        ループ.初期化する(1000/60);
        ループ.開始する();

        // 事前に読み込む画像の配列
        const 画像情報リスト = [
            { id: '草原', src: 'img/bg01.jpg' },
            { id: '人物01', src: 'img/chara01.png' },
            { id: '炎竜', src: 'img/mon01.png' },
            { id: 'デビル', src: 'img/mon02.png' }
        ];

        // ページ初期化時に画像をプリロード
        if (!await 画像管理.画像を読み込む(画像情報リスト)) return;

        // 画像の描画位置を設定
        const 背景01 = new スプライトクラス(レイヤー, 画像管理.取得する('草原'), 0, 0, 640, 640);

        const 人物01 = new スプライトクラス(レイヤー, 画像管理.取得する('人物01'), 0, 100, 640, 640);
        const 人物01正位置 = { x: 人物01.x, y: 人物01.y };
        人物01.座標を設定する(640, 100, 1280, 640); //初期表示位置を設定する

        const モンスター01 = new スプライトクラス(レイヤー, 画像管理.取得する('炎竜'), 0, 0, 640, 540);
        const モンスター01正位置 = { x: モンスター01.x, y: モンスター01.y };
        モンスター01.座標を設定する(-640, 0, 0, 540); //初期表示位置を設定する

        const モンスター02 = new スプライトクラス(レイヤー, 画像管理.取得する('デビル'), 0, 320, 320, 640);
        const モンスター02正位置 = { x: モンスター02.x, y: モンスター02.y };
        モンスター02.座標を設定する(640, -640, 960, 320); //初期表示位置を設定する

        const モンスター03 = new スプライトクラス(レイヤー, 画像管理.取得する('デビル'), 320, 320, 640, 640);
        const モンスター03正位置 = { x: モンスター03.x, y: モンスター03.y };
        モンスター03.座標を設定する(-320, -640, 0, 320); //初期表示位置を設定する

        ループ.処理を追加する(レイヤー, レイヤー.描画する.bind(レイヤー));

        let プロミスリスト;
        while (1) {
            await 人物01.移動して描画する(-40, 0, 人物01正位置.x, 0);
            await サンプル.一時停止(2000);

            プロミスリスト = [];
            プロミスリスト.push(人物01.移動して描画する(40, 0, 640, 0));
            プロミスリスト.push(モンスター01.移動して描画する(5, 0, モンスター01正位置.x, 0));
            プロミスリスト.push(モンスター02.移動して描画する(-20, 20, モンスター02正位置.x, モンスター02正位置.y));
            プロミスリスト.push(モンスター03.移動して描画する(10, 10, モンスター03正位置.x, モンスター03正位置.y));
            await Promise.all(プロミスリスト);
            await サンプル.一時停止(2000);

            プロミスリスト = [];
            プロミスリスト.push(モンスター01.移動して描画する(0, 10, 0, 640));
            プロミスリスト.push(モンスター02.移動して描画する(0, 5, 0, 640));
            プロミスリスト.push(モンスター03.移動して描画する(0, 20, 0, 640));
            await Promise.all(プロミスリスト);
            await サンプル.一時停止(2000);

            モンスター01.座標を設定する(-640, 0, 0, 540); //初期表示位置を設定する
            モンスター02.座標を設定する(640, -640, 960, 320); //初期表示位置を設定する
            モンスター03.座標を設定する(-320, -640, 0, 320); //初期表示位置を設定する
        }
    }

    static 一時停止(時間) {
        return new Promise(resolve =&amp;gt; setTimeout(resolve, 時間));
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;サンプルクラスは、これらのクラスを組み合わせて具体的な処理（ゲームやアニメーション）を実現する部分です。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p class=&quot;bold&quot;&gt;主な処理：&lt;/p&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;画像のプリロード：&lt;/span&gt;画像を事前に読み込むことで、スムーズな描画を実現します。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;スプライトの作成とアニメーション：&lt;/span&gt;スプライトをレイヤーに追加し、一定の方向に動かすアニメーションを行います。&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;bold&quot;&gt;一時停止と再開：&lt;/span&gt;awaitを使用して、一定時間停止した後に次のアニメーションを実行します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;await サンプル.一時停止(2000); 
// 2000ミリ秒（2秒）待ってから次の処理を実行します。
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;f.　初心者向けまとめ&lt;/h3&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;キャンバスは「描画用の黒板」のようなものです。&lt;/li&gt;
&lt;li&gt;レイヤーは「黒板を管理する管理人」で、黒板消しを持っています。&lt;/li&gt;
&lt;li&gt;スプライトは「黒板の上を動くキャラクターや背景」で、黒板消しは持っていないため、他のスプライトが描いたものに上書きすることはあっても、消すことはありません。&lt;/li&gt;
&lt;li&gt;ループは「描画を永遠に繰り返す仕組み」です。&lt;/li&gt;
&lt;li&gt;サンプルクラスで全てをつなぎ、画像の移動や停止、再開をコントロールします。&lt;/li&gt;
&lt;/ul&gt;
&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907701&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907701&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907701&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;&lt;/div&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E7%94%BB%E5%83%8F%E3%82%92%E7%A7%BB%E5%8B%95%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>
    <item>
      <title>画像を表示する方法</title>
      <description>&lt;div class=&quot;本文&quot;&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;Webブラウザのゲームを作る上で重要になる処理として、画像を表示する方法を記します。&lt;/li&gt;
&lt;li&gt;以下の画像は背景と人物の2枚の画像を重ねて表示しています。&lt;/li&gt;
&lt;li&gt;背景画像のサイズは480x480pxですが、640x640pxの領域に拡大して表示しています。&lt;/li&gt;
&lt;li&gt;人物画像は1024x1024pxですが、少し横長の640x540pxの領域に縮小かつ中央にして表示しています。&lt;/li&gt;
&lt;li&gt;このように、これから記す方法は画像を指定した領域に拡大したり、または縮小して表示することができます。&lt;/li&gt;
&lt;li&gt;また、JavaScriptで行っているのでゲーム内の好きなタイミングで表示したり、別の画像に差し替えたり出来ます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;iframe-container&quot;&gt;&lt;iframe width=&quot;656&quot; height=&quot;663&quot; style=&quot;border: 0;&quot; src=&quot;https://cf033538.cloudfree.jp/Game/sample01/sample.html&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;01　ファイル構成&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;それでは実際に処理を見ていきます。&lt;br /&gt;
先ずはファイル構成です。&lt;br /&gt;
ファイルとそれを入れるフォルダーを以下のような構成します。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;ファイル構成&quot;&gt;
&lt;ul class=&quot;list-13&quot;&gt;
&lt;li&gt;&lt;span&gt;sample01&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample01/sample.html&quot; target=&quot;_blank&quot;&gt;sample.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;js&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample01/js/sample.js&quot; target=&quot;_blank&quot;&gt;sample.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample01/js/imageManager.js&quot; target=&quot;_blank&quot;&gt;imageManager.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample01/js/sprite.js&quot; target=&quot;_blank&quot;&gt;sprite.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;img&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample01/img/statue.jpg&quot; target=&quot;_blank&quot;&gt;statue.jpg　※背景画像（480x480px）&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cf033538.cloudfree.jp/Game/sample01/img/chara_L.png&quot; target=&quot;_blank&quot;&gt;chara_L.png　※人物画像（1024x1024px）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;02　ファイル全体の流れ&lt;/h2&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;コード全体で行おうとしていることは以下の通りです。&lt;/p&gt;
&lt;ol class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;HTMLファイルに埋め込まれた &amp;lt;canvas&amp;gt; 要素に対して、JavaScriptを使って画像を描画します。&lt;/li&gt;
&lt;li&gt;画像管理クラス を使って画像をあらかじめ読み込みます（プリロード処理）。&lt;/li&gt;
&lt;li&gt;読み込んだ画像を スプライトクラス を使って描画します。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;これにより、動的にゲーム画面やイラストを操作する仕組みが出来上がります。&lt;/p&gt;
&lt;/div&gt;
&lt;h2 class=&quot;heading-018&quot;&gt;03　各部分の詳細解説&lt;/h2&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;a.　sample.html - HTMLファイル&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang=&quot;ja&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&amp;gt;
    &amp;lt;title&amp;gt;画像を表示する方法&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
    &amp;lt;script type=&quot;module&quot; src=&quot;js/sample.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;HTMLファイルは、 &amp;lt;canvas&amp;gt; という描画領域を作るための要素を用意しています：&lt;/p&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;&amp;lt;canvas class=&quot;レイヤー1&quot; width=&quot;640&quot; height=&quot;640&quot;&amp;gt;&amp;lt;/canvas&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;&amp;lt;canvas&amp;gt;の役割&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画面上に「絵を描くためのキャンバス」です。&lt;/li&gt;
&lt;li&gt;ここに画像を描画していきます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;b.　imageManager.js - 画像管理&lt;/h3&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;このファイルは、「画像を読み込んで管理するためのクラス」を定義しています。&lt;/p&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class 画像管理クラス {
    constructor() {
        this.画像キャッシュ = new Map();
    }

    async 画像を読み込む(画像情報リスト) {
        const プロミスリスト = 画像情報リスト.map(画像情報 =&amp;gt; {
            return new Promise((resolve, reject) =&amp;gt; {
                const 画像要素 = new Image();
                画像要素.src = 画像情報.src;

                画像要素.onload = () =&amp;gt; {
                    this.画像キャッシュ.set(画像情報.id, 画像要素);
                    resolve();
                };

                画像要素.onerror = () =&amp;gt; {
                    console.error(`画像が読み込めませんでした：${画像情報.src}`);
                    reject();
                };
            });
        });

        try {
            // 全ての画像が読み込まれるのを待つ
            await Promise.all(プロミスリスト);
            return true;
        } catch {
            return false;// 一つでも読み込めなかった場合
        }
    }

    取得する(id) {
        const 画像要素 = this.画像キャッシュ.get(id);
        if (!画像要素) console.error(`画像キャッシュにありません：${id}`);
        return 画像要素;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;1. クラスの宣言&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class 画像管理クラス {
    constructor() {
        this.画像キャッシュ = new Map();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;export: このクラスを他のJavaScriptのファイルからも使えるようにしています。&lt;/li&gt;
&lt;li&gt;constructor: この部分は、クラスが作られたときに呼ばれる特別な関数です。&lt;/li&gt;
&lt;li&gt;this.画像キャッシュ: Mapオブジェクトを使って、画像を保存しておきます。Mapは「キー」と「値」をペアで管理する便利なデータ構造です。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;2. 画像を読み込む() 関数&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;async 画像を読み込む(画像情報リスト) {
    const プロミスリスト = 画像情報リスト.map(画像情報 =&amp;gt; {
        return new Promise((resolve, reject) =&amp;gt; {
            const 画像要素 = new Image();
            画像要素.src = 画像情報.src;
            画像要素.onload = () =&amp;gt; {
                this.画像キャッシュ.set(画像情報.id, 画像要素);
                resolve();
            };
            画像要素.onerror = () =&amp;gt; {
                console.error(`画像が読み込めませんでした：${画像情報.src}`);
                reject();
            };
        });
    });

    try {
        await Promise.all(プロミスリスト);
        return true;
    } catch {
        return false;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;この関数の役割:&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;複数の画像を「並列処理」で読み込みます。これにより、全ての画像を同時に効率よく読み込むことができます。&lt;/li&gt;
&lt;li&gt;画像は読み込み完了後に「画像キャッシュ」に保存されます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;細かい説明:&lt;br /&gt;
&lt;ol class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画像情報リスト.map():&lt;br /&gt;

&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;画像情報リストの各画像について1つずつPromiseを作ります。&lt;/li&gt;
&lt;li&gt;Promiseは「画像の読み込み完了を待たずに進む」という非同期処理を行います。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Promise の内容:&lt;br /&gt;

&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;読み込みたい画像ファイルのパスを指定し、画像要素という新しいImageオブジェクトを作ります。&lt;/li&gt;
&lt;li&gt;画像が正常に読み込まれた場合、resolve()を呼び出して成功として動作します。&lt;/li&gt;
&lt;li&gt;エラーがあった場合は、reject()を呼び出してエラーとして動作します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Promise.all():&lt;br /&gt;

&lt;ul class=&quot;箇条書き3&quot;&gt;
&lt;li&gt;全てのPromiseの処理結果を受け取る仕組みです。&lt;/li&gt;
&lt;li&gt;どれか1つでもエラーがあれば、全体が失敗として扱われます。&lt;/li&gt;
&lt;li&gt;この関数にawaitをつけて、かつ「画像を読み込む()」関数にasyncをつけることで、全てのPromiseの処理結果を待つようになります。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;3. 取得する() 関数&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;取得する(id) {
    const 画像要素 = this.画像キャッシュ.get(id);
    if (!画像要素) console.error(`画像キャッシュにありません：${id}`);
    return 画像要素;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;この関数の役割:&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;引数で渡された id を使って、画像キャッシュから特定の画像を取り出します。&lt;/li&gt;
&lt;li&gt;見つからない場合はエラーを表示します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;動き方:&lt;br /&gt;
&lt;ol class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;this.画像キャッシュ.get(id) でキャッシュを確認します。&lt;/li&gt;
&lt;li&gt;画像があればそれを返し、なければエラーを表示します。&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;4. 初心者向けのポイント&lt;/span&gt;&lt;/h4&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;非同期処理を同期させる (async と await):&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;時間がかかる処理（例: サーバーから画像データを取得する処理）を非同期で行っている場合に、その処理を待つために使います。&lt;/li&gt;
&lt;li&gt;これにより、非同期の処理を順番どおり（同期的）に実行できるようになります。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Mapオブジェクト:&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;キー（ここでは id）を使ってデータを管理できます。&lt;/li&gt;
&lt;li&gt;例えば、「キーが &quot;背景画像&quot; のときはこの画像を取り出す」といった処理が簡単に行えます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;c.　sprite.js - 描画処理&lt;/h3&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;このファイルは、「画像をキャンバス上の指定した位置に表示するためのクラス」を定義しています。&lt;/p&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;export class スプライトクラス {
    constructor(canvas) {
        this.ctx = canvas.getContext('2d');
    }

    描画する(画像要素, x1, y1, x2, y2) {
        const 表示幅 = x2 - x1;
        const 表示高さ = y2 - y1;

        const 画像縦横比 = 画像要素.width / 画像要素.height;
        const 表示縦横比 = 表示幅 / 表示高さ;

        let 描画幅, 描画高さ, 位置調整X, 位置調整Y;

        if (画像縦横比 &amp;gt; 表示縦横比) {
            描画幅 = 表示幅;
            描画高さ = 表示幅 / 画像縦横比;
            位置調整X = 0;
            位置調整Y = (表示高さ - 描画高さ) / 2; // 垂直中央揃え
        } else {
            描画高さ = 表示高さ;
            描画幅 = 表示高さ * 画像縦横比;
            位置調整X = (表示幅 - 描画幅) / 2; // 水平中央揃え
            位置調整Y = 0;
        }

        this.ctx.drawImage(画像要素, x1 + 位置調整X, y1 + 位置調整Y, 描画幅, 描画高さ); // 画像を描画
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;1. 縦横比を維持して画像を中央揃えにする処理&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;if (画像縦横比 &amp;gt; 表示縦横比) {
    // 横長画像の場合
    描画幅 = 表示幅;
    描画高さ = 表示幅 / 画像縦横比;
    位置調整Y = (表示高さ - 描画高さ) / 2; // 垂直中央
} else {
    // 縦長画像の場合
    描画高さ = 表示高さ;
    描画幅 = 表示高さ * 画像縦横比;
    位置調整X = (表示幅 - 描画幅) / 2; // 水平中央
}
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;縦横比の計算:&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画像の元々の縦横比を計算し、それを使って適切なサイズに縮小または拡大します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;中央揃え:&lt;br /&gt;

&lt;ul class=&quot;箇条書き2&quot;&gt;
&lt;li&gt;画像の描画位置を調整して、表示領域の中央に配置します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;2. 画像を描画する&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;this.ctx.drawImage(画像要素, x1 + 位置調整X, y1 + 位置調整Y, 描画幅, 描画高さ);
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;drawImage メソッド: 指定した位置（表示したい領域の左上の座標）とサイズ（幅と高さ）に画像を描画します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h3 class=&quot;heading-23&quot;&gt;d.　sample.js - メインの処理&lt;/h3&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;import { 画像管理クラス } from './imageManager.js'; // クラスをインポート
import { スプライトクラス } from './sprite.js'; // クラスをインポート

class サンプル {
    static async main() {
        const canvas = document.querySelector('canvas.レイヤー1');
        const スプライト = new スプライトクラス(canvas);
        const 画像管理 = new 画像管理クラス();

        // 事前に読み込む画像の配列
        const 画像情報リスト = [
            { id: '像の背景', src: 'img/statue.jpg' },
            { id: '人物01', src: 'img/chara_L.png' }
        ];

        // ページ初期化時に画像をプリロード
        if (!await 画像管理.画像を読み込む(画像情報リスト)) return;

        // プリロード完了後に画像を描画
        スプライト.描画する(画像管理.取得する('像の背景'), 0, 0, 640, 640);
        スプライト.描画する(画像管理.取得する('人物01'), 0, 100, 640, 640);
    }
}

addEventListener('load', サンプル.main);
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;p&gt;以下の流れでコードが進みます：&lt;/p&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;1. キャンバスと描画に必要なクラスを準備&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const canvas = document.querySelector('canvas.レイヤー1');
const スプライト = new スプライトクラス(canvas);
const 画像管理 = new 画像管理クラス();
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;document.querySelector(): HTML内の特定の要素（ここでは &amp;lt;canvas&amp;gt;）を取得します。&lt;/li&gt;
&lt;li&gt;スプライトクラス: 画像を描画する役割を持つクラスです。&lt;/li&gt;
&lt;li&gt;画像管理クラス: 画像を管理・読み込みするクラスです。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;2. 画像のプリロード処理&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;const 画像情報リスト = [
    { id: '像の背景', src: 'img/statue.jpg' },
    { id: '人物01', src: 'img/chara_L.png' }
];
if (!await 画像管理.画像を読み込む(画像情報リスト)) return;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;画像情報リスト: 読み込む画像のファイル名を指定します。&lt;/li&gt;
&lt;li&gt;await 画像管理.画像を読み込む(): すべての画像が読み込まれるまで処理を待ちます。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4 class=&quot;heading-33&quot;&gt;&lt;span&gt;3. 画像の描画処理&lt;/span&gt;&lt;/h4&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;code&gt;スプライト.描画する(画像管理.取得する('像の背景'), 0, 0, 640, 640);
スプライト.描画する(画像管理.取得する('人物01'), 0, 100, 640, 640);
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;本文&quot;&gt;
&lt;ul class=&quot;箇条書き1&quot;&gt;
&lt;li&gt;スプライト.描画する(): 指定した座標（左上と右下の座標を指定）に画像を描画します。&lt;/li&gt;
&lt;li&gt;画像管理.取得する(): 画像キャッシュから指定した画像を取得します。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;!--shinobi1--&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//xa.shinobi.jp/ufo/191907700&quot;&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href=&quot;//xa.shinobi.jp/bin/gg?191907700&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;//xa.shinobi.jp/bin/ll?191907700&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;span style=&quot;font-size:9px&quot;&gt;&lt;img style=&quot;margin:0;vertical-align:text-bottom;&quot; src=&quot;//img.shinobi.jp/tadaima/fj.gif&quot; width=&quot;19&quot; height=&quot;11&quot;&gt; &lt;/span&gt;&lt;/noscript&gt;&lt;!--shinobi2--&gt;&lt;/div&gt;</description> 
      <link>https://cript.game-ss.com/javascript%E7%B4%B9%E4%BB%8B/%E7%94%BB%E5%83%8F%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95</link> 
    </item>

  </channel>
</rss>