Getting something displayed

The last Tutorial was about the general setup of FIFErpg projects and ended with getting a black window displayed. Since that is not very interesting this tutorial will be about loading and displaying maps.

Maps

FIFErpg uses the normal FIFE map files for the static non-interactive objects of a map and thus the first thing needed is an actual map. If you don’t have a map yourself you can download this archive. Extract that archive to the directory where your settings-dist.xml is. It should create a maps and a objects directory. The latter contains the graphics for the map. The map itself is in the maps directory. It is the same map that is used in the RPG demo of FIFE.

New Settings

Before this map can be loaded you need to add settings to your settings-dist.xml. The first is a ‘Camera’ setting. This is the camera that will be used after loading the map. For the downloaded map this is ‘camera1’. Change this if you use a different map. The second is the ‘Components’ setting. This is a list that tells FIFErpg which components are used by the application. This will be explained more later. For now the list only needs to contain ‘Agent’.

You can verify with the updated settings-dist.xml file.

+ show/hide contents
<?xml version='1.0' encoding='UTF-8'?>
<Settings>
	<Module name="FIFE">
		<Setting name="FullScreen" type="bool"> False </Setting>
		<Setting name="PlaySounds" type="bool"> True </Setting>
		<Setting name="RenderBackend" type="str"> OpenGL </Setting>
		<Setting name="ScreenResolution" type="str">1024x768</Setting>
		<Setting name="BitsPerPixel" type="int"> 0 </Setting>
		<Setting name="InitialVolume" type="float"> 5.0 </Setting>
		<Setting name="SDLRemoveFakeAlpha" type="int"> 1 </Setting>
		<Setting name="GLCompressImages" type="bool"> False </Setting>
		<Setting name="WindowTitle" type="str"> FIFErpg Tutorial </Setting>
		<Setting name="WindowIcon" type="str"> </Setting>
		<Setting name="Font" type="str"> fonts/FreeSans.ttf </Setting>
		<Setting name="FontGlyphs" strip="0" type="str"> abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&amp;`'*#=[]\"</Setting>
		<Setting name="DefaultFontSize" type="int"> 16 </Setting>
		<Setting name="LogModules" type="list"> controller ; script </Setting>
		<Setting name="PychanDebug" type="bool"> False </Setting>
		<Setting name="LogToPrompt" type="int"> 1 </Setting>
 		<Setting name="UsePsyco" type="bool"> False </Setting>
		<Setting name="ProfilingOn" type="bool"> False </Setting>
		<Setting name="LogToFile" type="int"> 0 </Setting>
    	<Setting name="Lighting" type="int"> 0 </Setting>
	</Module>
	<Module name="fife-rpg">
    	<Setting name="ProjectName" type="str">Tutorial 2</Setting>
    	<Setting name="Camera" type="str">camera1</Setting>
        <Setting name="Components" type="list">Agent</Setting>
    </Module>
</Settings>

New Files

There are also new definition files that need to be created. First you need a file that contains a list of what components are available and what names they have. That file is a YAML file with a simple structure:

Components:
   <component_name>: <python path to the component module>

Example:

Components:
   Agent: fife_rpg.components.agent

combined.yaml contains the standard FIFErpg components, as well as a list of systems, actions and behaviours which will be explained later. Also a list of the available map is needed. By default FIFErpg looks for a ‘maps.yaml’ file inside the ‘maps’ subdirectory. This is a simple YAML file with that has the following structure:

Maps:
   <name of the map>: <filename of the map, without the extension>

Example:

Maps:
   Level1: "level1"

The above example is also what is needed for this tutorial, but you can download the file here.

The code

With those changes down we can get to the additions to the code.

The components have to be loaded and activated after creating the application and before creating the world. After creating the application here:

app = RPGApplication(settings)

Add the following lines:

app.load_components("combined.yaml")
app.register_components()

load_components("combined.yaml") loads the components that are in the “combined.yaml” file and adds them to an internal list.

register_components() registers the components that are set in the ‘Components’ setting.

The maps can be loaded and activated anywhere between creating the world and running the main loop of the application. After the line:

app.create_world()

Add the following:

app.load_maps()
app.switch_map("Level1")

load_maps() loads the list of maps from the maps.yaml file.

switch_map("Level1") changes the active map to “Level1”.

Here is the complete code:

from fife_rpg import RPGApplication
from fife_rpg import GameSceneView
from fife_rpg import GameSceneController
from fife.extensions.fife_settings import Setting

settings = Setting(app_name="Tutorial 2", settings_file="settings.xml")

def main():
    app = RPGApplication(settings)
    app.load_components("combined.yaml")
    app.register_components()
    view = GameSceneView(app)
    controller = GameSceneController(view, app)
    app.create_world()
    app.load_maps()
    app.switch_map("Level1")
    app.push_mode(controller)
    app.run()

if __name__ == '__main__':
    main()

If you run this code you should see something like this:

../_images/screenshot.png

Empty map. This may vary if you used a different map.

If it appears that there are graphical problems you might want to check out the Known Problems section of FIFE.

In the next part of the Tutorial we will be adding the Dynamic objects to the map.