Instance Renderer

From FIFE development wiki
Jump to: navigation, search

Introduction

The InstanceRenderer is used for the main render part of FIFE. It draws, layer based, all instances that have a visual to the screen. The renderer is enabled by default and all Layers are set to active. You can set a Instance or Layer to be total or semi transparent, in case of total transparency the Layer or Instance is not rendered. In some special cases it could happen that the z-ordering is not working correct for you e.g. if two or more Instances on the same Layer share its position. You can manipulate the ordering by InstanceVisual stack position.

In addition, there are functions to outline, coloring the Instance or you can give it a transparent area or prevent it from light. If additional images are created e.g. for outlines, they will be cached. If they are no longer needed they are freed after a period of time (default is 60 seconds).

Usage

The biggest part happens automatically when you load the map. So here I will describe the special functions you can use.

Outlines

With Outlines you can highlight Instances. To achieve this, a "line" is drawn around the image. You can set the color and the width which are then used, also the threshold, where the lines begin, can be configured.

Coloring

This mix the Instance Image with a settable color in the ratio 1:1. If you use OpenGL and have MultiTexture support then this feature is used to achieve this effect.

Transparent Areas

You can add a transparent area to your Instance. The effect is that all other instances thats intersects this area and have the given namespace be made transparent.

Ignore Light

In some cases it can be useful to prevent an Instance from light. You can set a list of namespaces, all instances which use one of these spaces are not illuminated.


Options

getName()

string; gets the name of the renderer


addOutlined(instance, r, g, b, width, threshold = 1)

adds a outline to the instance

instance
fife.Instance; the used instance
r,g,b
integer; color values, range 0-255
width
integer; width of the outline
threshold
integer; threshold alpha value, where the outline starts


removeOutlined(instance)

removes a outline from the instance

instance
fife.Instance; the used instance


removeAllOutlines()

removes all outlines


addColored(instance, r, g, b)

adds coloring to the instance

instance
fife.Instance; the used instance
r,g,b
integer; color values, range 0-255


removeColored(instance)

removes coloring from the instance

instance
fife.Instance; the used instance


removeAllColored()

removes all colorings


addTransparentArea(instance, namespaces, w, h, transparent, front=True)

adds transparent area to the instance

instance
fife.Instance; the used instance
namespaces
string list; list that contain namespaces whose instances should be transparent
w, h
integer; width and heigth of the area
transparent
integer; alpha value for transparents, range 0-255
front
bool; if it is set to true, only instances in front(below) of it are transparent


removeTransparentArea(instance)

removes transparent area from the instance

instance
fife.Instance; the used instance


removeAllTransparentAreas()

removes all transparent areas


addIgnoreLight(namespaces)

adds namespaces whose instances ignore the light

namespaces
string list; list that contain namespaces whose instances should ignore the light


removeIgnoreLight(namespaces)

removes namespaces

namespaces
string list; list that contain namespaces whose should removed


removeAllIgnoreLight()

removes all namespaces


setRemoveInterval(interval)

sets the timer interval in seconds, after this interval unused extra images are freed

interval
integer; defines in second the interval to freeing the unused images, default is 60


getRemoveInterval()

return the interval in seconds, default is 60


Example

Here we add an outline to our hero instance with the color red and width=5.

 # self.hero.instance is an instance of fife.Instance()
 # self.camera is an instance of fife.Camera()
 
 #get renderer
 renderer = fife.InstanceRenderer.getInstance(self.camera)
 
 #add outline to instance
 renderer.addOutlined(self.hero.instance, 255, 0, 0, 5)