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

7.8.4 Sprite2D Mesh Object

Written by Jorrit Tyberghein, (jorrit.tyberghein@uz.kuleuven.ac.be).

A 2D Sprite is basically a polygon that always faces the camera. There are some special effects that you can do with this but it is really very simple otherwise.

Basic Structure

The following SCF class names are used (for CS_LOAD_PLUGIN()):

Objects in this plugin implement the following SCF interfaces (get with SCF_QUERY_INTERFACE()):

Factory State Interface

`iSprite2DFactoryState' is the SCF interface that you can use to set/get settings for a 2D sprite factory. The definition of this interface can be found in `CS/include/imspr2d.h' and that is also the include file you need to include in your applications to use this plugin. Using this interface you can access the material, blending mode (mixmode), and lighting settings.

Factory Loader

LIGHTING
Enable/disable lighting.
MATERIAL
Material to use for the polygon.
MIXMODE
Blending mode; one of `ADD', `ALPHA', `COPY', `KEYCOLOR', `MULTIPLY2', `MULTIPLY', or `TRANSPARENT'.
UVANIMATION
Define an uv animation, that is a sequence of frames which textures are all in one big texture. Thus the animation is achieved by altering the (u,v) coordinates of the polygon defined by this sprite.
FRAME
Defines a single frame within an uv animation by specifying its duration in milliseconds and the u,v coordinates to use.

Object State Interface

`iSprite2DState' is the SCF interface that you can use to set/get settings for a 2D sprite object. The definition of this interface can be found in `CS/include/imspr2d.h' and that is also the include file you need to include in your applications to use this plugin. Using this interface you can access the material, blending mode (mixmode), lighting settings, and also the vertices of the 2D polygon controlled by this plugin.

Object Loader

FACTORY
Name of the factory to use for creation of this instance.
MIXMODE
Blending mode, one of `ADD', `ALPHA', `COPY', `KEYCOLOR', `MULTIPLY2', `MULTIPLY', or `TRANSPARENT'.
MATERIAL
Material to use for the polygon.
LIGHTING
Enable/disable lighting.
VERTICES
List of 2D vertices defining the polygon.
UV
List of texture mapping UV coordinates for the polygon.
COLORS
List of rgb colors for the polygon.
ANIMATE
Select an uv animation from the list of animations declared in the template

Example 1

This is how our world file looks:

 
WORLD (
  TEXTURES (
    TEXTURE 'blow' (FILE(blow.png))
  )

  MATERIALS (
    MATERIAL 'explosion' (TEXTURE ('blow'))
  )

  MESHOBJ 'Explosion' (
    PLUGIN ('crystalspace.mesh.loader.factory.sprite.2d')
    PARAMS (
      MATERIAL ('explosion')
      UVANIMATION 'boom' (
        FRAME 'f1' ( 100, 0, 0, 0.5, 0, 0.5, 0.5, 0, 0.5)
        FRAME 'f2' ( 100, 0.5, 0, 1, 0, 1, 0.5, 0.5, 0.5)
        FRAME 'f3' ( 100, 0, 0.5, 0.5, 0.5, 0.5, 1, 0, 1)
        FRAME 'f4' ( 100, 0.5, 0.5, 1, 0.5, 1, 1, 0.5, 1)
      )
    )
  )

  sector 'space' (
    ; define all the stuff in space
    ; ...
    ; and now one of the enemies right after we met him
    MESHOBJ 'kaboom' (
      PLUGIN ('crystalspace.mesh.loader.sprite.2d')
      PARAMS (
        FACTORY ('Explosion')
        VERTICES (-1,1,1,1,1,-1,-1,-1)
        UV (0,0,1,0,1,1,0,1)
        COLORS (1,1,1,1,1,1,1,1,1,1,1,1)
	LIGHTING (no)
        ; show the animation, use the timings attached to
	; the frames, loop
        ANIMATE ('boom', 0, yes)
      )
      MOVE (0,0,0)
    )
  )  
)


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

This document was generated using texi2html