4.2.2.1 メモリ上への構成要素の読み込み


4.2.2.1 メモリ上への構成要素の読み込み

To make this example a little more interesting the material is going to be loaded after the other set-up of the texture manager has been performed. This is not really needed but it illustrates how a game might load materials dynamically after the application is already running. So, first we edit `simple.h':

この例にもう少し興味をもってもらうために、 テクスチャマネージャの一方のセットアップ完了後に、構成要素を読み込みます。これは本当は必要ではないですが、どのように、ゲームがアプリケーション実行後、動的に構成要素を読み込むか、説明します。さあ、まず、`simple.h`を変更しましょう。

...
class Simple
{
private:
 ...
 void CreateSprites ();
 ...

Then, we edit `simple.cpp' and add the following in Simple::Application() and Simple::CreateSprites?() (before `return true'):

そして、`simple.cpp`を編集します。以下に示す2つの関数に、次に示すものを追加します。追加する場所は、`return true`の前です。

  • Simple::Application()
  • Simple::CreateSprites?()
bool Simple::Application()
{
 ...
 CreateSprites();
 ...
 return true;
}

...

void Simple::CreateSprites()
{
 // Load a texture for our sprite.
 iTextureWrapper* txt = loader->LoadTexture ("spark",
       "/lib/std/spark.png");
 if (txt == 0)
   ReportError("Error loading texture!");
}

This code first loads a texture with iLoader::LoadTexture?(). The second argument is the file name for our texture (VFS path) and the first argument is how that texture should be named in the engine. In this case we use "spark" for that because that's how the `sprite1' definition wants it.

このコードでは、まず、iLoader::LoadTexture?()で1枚のテクスチャを読み込んでいます。第2引数は、VFSパスにあるテクスチャのファイル名です。第1引数は、エンジンが持つテクスチャ名です。この例では、"spark"というテクスチャ名を使います。なぜなら、`sprite1`の定義の中で使用しているテクスチャ名だからです。

If loading succeeds this function will register our texture with the texture manager so it can be immediatelly used.

読み込みに成功した場合、この関数は、テクスチャをテクスチャマネージャに登録します。そのため、テクスチャを即座に使用することができます。

Further note that when you load a texture like this, there will also be an associated material with the same name. The engine itself works with materials and doesn't directly use textures. The material in this case is simply a wrapper on top of the texture. But you could also add detail textures.

なお、注意してください。このようにテクスチャを読み込んだ時、同じ名前を使用して、構成要素を関連ずけます。エンジンは、構成要素を扱う仕事をします。そして、テクスチャを直接は使用しません。この例の構成要素は、単純なテクスチャを処理するラッパーです。しかし、あなたは詳細なテクスチャを追加することもできます。

最新の20件

2007-02-18 2007-02-12 2007-01-31 2007-02-12 2007-01-14 2007-01-21 2007-02-12 2007-02-11 2007-01-15 2007-01-14 2007-02-12 2007-02-11 2007-02-01 2007-01-21 2007-01-19 2007-02-12 2007-01-19 2009-08-27 2007-01-10

今日の16件

  • counter: 117
  • today: 1
  • yesterday: 0
  • online: 4