class KSprite

The main KDE game object. More...

Definition#include <kspritecache.h>
InheritsQCanvasSprite (unknown) [public ]
List of all Methods
Annotated List

Public Methods

Detailed Description

The KSprite class is an advance QCanvasSprite class which is usable with the KSpriteCache. It furthermore contains a few useful functions like advanced movement and animations which go beyond the QCanvasSprite versions of them. Also it provides a signal which is emitted when movement or animation are finished.

 KSprite (QCanvasPixmapArray* array, QCanvas* canvas)


Contructs a KSprite object. It is anlogous to the QCanvasSprite constructor

array- the frames of the sprite
canvas- the canvas the sprites lives on

 ~KSprite ()



Destructs the sprite

int  rtti ()



The sprites runtime idendification (32)

QCanvasPixmapArray*  images ()



returns a pointer to the pixmap array which holds the frames of the sprite.

void  moveTo (double x,double y,double speed=0.0)


Moves the sprite to the given position with the given speed. When it reaches its desitnation a signal is emmited if the emmiter createNotify is enabled

x- the x coordinate
y- the y coordinate
speed- the speed to move . If zero the last set speed is taken

void  advance (int stage)


The sprites advance function. See the qt QcanvasSprite advance

void  setSpeed (double v)


Sets the speed for the next move. Can be set with moveTo too.

v- the speed in pixel per animation cycle

double  speed ()


returns the speed

QObject * notify ()


returns the notification QObject. You probably do not need this but createNotify instead

QObject * createNotify ()


Creates a notification object. You can connect to it and it will emit the signal signalNotify(QCanvasItem *parent, intmode) when a move or animation is finished. Example:

  connect(sprite->createNotify(),SIGNAL(signalNotify(QCanvasItem *,int)),
          this,SLOT(moveDone(QCanvasItem *,int)));

In the move done function you best delete the notify again with deleteNotify

void  deleteNotify ()


Deletes the sprite notify if it is no longer used. The notify keeps a reference count which deletes the QObject when no reference to it is in use.

void  getAnimation (int no,int &startframe,int &endframe,int &mode,int &delay)


Reads the animation parameters into the given variables for the given animation. Mostly used by KSpriteCache

no- the animation number
startframe- the first frame of the animation
endframe- the last frame of the animation
mode- the mode of the animation see creaetAnimation
delay- the delay in QCanvas animation cycles between two frames

void  createAnimation (int no,int startframe,int endframe,int mode,int delay)


Creates an animation of the sprite between two frames in one of the following modes 0: no animation 1: single shot a->b -1: single shot b->a 2: cycle a->b->a -2: cycle b->a->b 3: cycle a->b -3: cycle b->a

The single shot animations will emit the above mentioned signal over the notify object if it is created. If you load the sprite over the KSpriteCache's config file you need not bother about calling this function.

void  setAnimation (int no)


Switches on the animation of the given number. Of course it needs to be defined beforehand either via loading the sprite with the KSpriteCache or be calling createAnimation

no- the number of the animation

unsigned int  animationCount ()


Returns how many different animations are stored