Historique des modifications - Message

Message #10431

Sujet: setLoopMode(false) ne fait pas du tout l'animation


Type Date Auteur Contenu
Création du message 04-04-2012 14:15:03 johnplayer
Tiens voici un code qui marche (je l'ai testé), j'y ai mis quelques explications :

#include <irrlicht.h>
//#include "pthread.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

IAnimatedMeshSceneNode* ANode;


class MyEventReceiver : public IEventReceiver
{
    public :

        MyEventReceiver(IrrlichtDevice *device) : Device(device) {}

        IrrlichtDevice *Device;

        virtual bool OnEvent(const SEvent& event)
        {
            if (event.EventType == EET_MOUSE_INPUT_EVENT)
            {
                switch(event.MouseInput.Event)
                {
                    case EMIE_LMOUSE_PRESSED_DOWN:
                    {
                        ///
                    }
                    break;
                    case EMIE_RMOUSE_PRESSED_DOWN:
                    {
                        ///
                    }
                    break;
                    default:
                    break;
                }
            }

            if (event.EventType == EET_KEY_INPUT_EVENT)
            {
                if(event.KeyInput.PressedDown)
                {
                    switch(event.KeyInput.Key)
                    {
                        case KEY_ESCAPE:
                            Device->closeDevice();                  // QUITTE L'APPLICATION
                        break;

                        case KEY_KEY_A:
                        {
                            ANode->setFrameLoop(0,13); // walk
                        }
                        break;

                        case KEY_KEY_Z:
                        {
                            ANode->setFrameLoop(146,148); // backflip
                        }
                        break;

                        case KEY_SPACE:
                        {
                            ANode->setFrameLoop(94,102); // jump
                        }
                        break;

                        default:
                        break;
                    }
                }
            }

            return false;
        }

};


int main(int argc, char** argv)
{
    // fenetre
    IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2du(1280, 720), 32, false, false, false, 0);

    MyEventReceiver* receiver = new MyEventReceiver(device);
    device->setEventReceiver(receiver);

    device->setWindowCaption(L"Fenetre principale");

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    // dessin à réalisé dans la fenetre
    ANode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("./media/ninja.b3d"));
    ANode->setMaterialTexture(0, driver->getTexture("./media/nskinbl.jpg"));
    ANode->setMaterialFlag(EMF_LIGHTING, false);
    ANode->setMaterialFlag(EMF_NORMALIZE_NORMALS, false);
    ANode->setAnimationSpeed(10);
    ANode->setLoopMode(false); // il ne joue l'animation qu'une fois par appel
    ANode->setFrameLoop(0,0); // position de départ

    // caméras
    smgr->addCameraSceneNodeFPS();

    // dessin fenetre
    while(device->run())
    {
        // teste si l'animation est arrivée à sa fin
        if( ANode->getFrameNr() == ANode->getEndFrame() )
        {
            // alors on remet le personnage à la frame 0
            ANode->setFrameLoop(0,0);
            /** ATTENTION
            ANode->setCurrentFrame(0); remmetterait l'animation en route car irrlicht voit que la frame courante et différent de celle de fin
             **/
        }
            

        // fenetre
        driver->beginScene(true, true, SColor(0,200,200,200));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();

    }

    device->drop();

    return 0;
}

Il suffit de reculer un peu pour voir le personnage et appuies sur les A, Z ou ESPACE pour déclencher une animation.
S'il y a quelque chose que tu comprends pas, il n'y a qu'à demander.

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
115 invités en ligne
membre en ligne: -
RSS Feed