[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] [ Search: ]

4.16.1 Loading a Level

This section describes how you can load a level in your game.

Getting the Level Loader Plugin

To load a level you need the level loader plugin. There are two ways to make sure you have this plugin in your application. You can put a line in your config file like this:

System.Plugins.iLoader = crystalspace.level.loader

Or you can add the following line to the call to csInitializer::RequestPlugins() in your main() function:


To finally be able to use the level loader in your application you need to do:

csRef<iLoader> level_loader = csQueryRegistry<iLoader> (object_reg);

When you don't need it anymore you must call level_loader.Invalidate ().

Loading a Map

Loading a map is simple. You just do:

VFS->ChDir ("/lev/mymap");
level_loader->LoadMapFile ("world");
engine->Prepare ();

This will first set the current directory to the right VFS dir (see section Virtual File System (VFS)) and then it will load the map file which is called 'world' (this is not a requirement).

Note that this will clear all other geometry that might have been loaded in the engine before. If you don't want that then you need to set the second parameter of LoadMapFile to false.

The line engine->Prepare() will make sure that everything that is loaded is correctly set up (i.e. materials and texture will be registered).

Include Files

The include files useful for this section are:

#include <isys/vfs.h>
#include <imap/loader.h>
#include <iengine/engine.h>

This document was generated using texi2html 1.76.