Historique des modifications - Message

Message #8328

Sujet: Savoir quand l'animation est terminé


Type Date Auteur Contenu
Création du message 03-07-2010 12:42:45 Zorian
J'ai trouvé comment marchait OnAnimationEnd().
Tout fonctionne bien avec ce code (qui n'est pas très interressant si ce n'est pour découvrir le fonctionnement de OnAnimationEnd).

Main.cpp
#include <irrlicht.h>
#include "CAnimationEndCallBack.h"

using namespace irr;

int main(void)
{
    IrrlichtDevice *device = createDevice (video::EDT_OPENGL, core::dimension2d<u32>(800,600),32,false,true,false,0);
    video::IVideoDriver* driver = device->getVideoDriver ();
    scene::ISceneManager *smgr = device->getSceneManager ();

    smgr->addCameraSceneNodeFPS();

    scene::IAnimatedMesh *mesh = smgr->getMesh("sydney.md2");
    scene::IAnimatedMeshSceneNode *node = smgr->addAnimatedMeshSceneNode(mesh);

    node->setFrameLoop(1,15); //on définit la boucle d'animation
    node->setLoopMode(false); //on désactive la répétition

    CAnimationEndCallBack *anim  = new CAnimationEndCallBack(); //on crée un AnimationEndCallBack
    node->setAnimationEndCallback(anim); //et on l'assigne au node

    while (device->run ())
    {
        driver->beginScene(true, true, video::SColor(255,255,255,255));
        smgr->drawAll();
        driver->endScene();
    }

    device->drop ();
    return 0;
}

CAnimationCallBack.h
#ifndef CANIMATIONENDCALLBACK_H_INCLUDED
#define CANIMATIONENDCALLBACK_H_INCLUDED

#include <irrlicht.h>

using namespace irr;

class CAnimationEndCallBack : public scene::IAnimationEndCallBack
{
    public :

    CAnimationEndCallBack();
    ~CAnimationEndCallBack();

    void OnAnimationEnd(scene::IAnimatedMeshSceneNode* node);

    private :

    bool animationFinie; 

};

#endif // CANIMATIONENDCALLBACK_H_INCLUDED

CAnimationCallBack.cpp
#include "CAnimationEndCallBack.h"


CAnimationEndCallBack::CAnimationEndCallBack() : animationFinie(false)
{
}

CAnimationEndCallBack::~CAnimationEndCallBack()
{
}

void CAnimationEndCallBack::OnAnimationEnd(scene::IAnimatedMeshSceneNode *node)
{
    if(!animationFinie)
    {
        //tu sais que l'animation est maintenant finie, tu as un pointeur vers le node pour les modifications que tu souhaites faire
        animationFinie = true;
    }
}

Pour résumer, OnAnimationEnd est automatiquement appelé à la fin de l'animation de ton personnage si la répétition de la boucle est désactivée et si tu lui as assigné un AnimationEndCallBack.
Après, ça oblige à refaire une classe juste pour redéfinir OnAnimationEnd.

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
187 invités en ligne
membre en ligne: -
RSS Feed