|
|
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)
| KSprite |
Contructs a KSprite object. It is anlogous to the QCanvasSprite constructor
Parameters:
| array | - the frames of the sprite |
| canvas | - the canvas the sprites lives on |
| ~KSprite ()
| ~KSprite |
[virtual]
Destructs the sprite
| int rtti ()
| rtti |
[const]
The sprites runtime idendification (32)
| QCanvasPixmapArray* images ()
| images |
[const]
returns a pointer to the pixmap array which holds the frames of the sprite.
| void moveTo (double x,double y,double speed=0.0)
| moveTo |
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
Parameters:
| 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)
| advance |
The sprites advance function. See the qt QcanvasSprite advance
| void setSpeed (double v)
| setSpeed |
Sets the speed for the next move. Can be set with moveTo too.
Parameters:
| v | - the speed in pixel per animation cycle |
| double speed ()
| speed |
returns the speed
| QObject * notify ()
| notify |
returns the notification QObject. You probably do not need this but createNotify instead
| QObject * createNotify ()
| 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 ()
| 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)
| getAnimation |
Reads the animation parameters into the given variables for the given animation. Mostly used by KSpriteCache
Parameters:
| 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)
| createAnimation |
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)
| setAnimation |
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
Parameters:
| no | - the number of the animation |
| unsigned int animationCount ()
| animationCount |
Returns how many different animations are stored