i succed to make an exemple like tuto but when i put it in my code, it crash
if you want that's is the new code:
character.h
Code: Select all
#ifndef CHARACTER_H
#define CHARACTER_H
#include "Login.h"
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
struct SAppContext
{
IrrlichtDevice *device;
};
// Define some values that we'll use to identify individual GUI controls.
enum
{
GUI_ID_VAL1,
GUI_ID_VAL2,
GUI_ID_VAL3
};
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(SAppContext & context) : Context(context) { }
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = Context.device->getGUIEnvironment();
if(event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{
if (id == GUI_ID_VAL1 || id == GUI_ID_VAL2 || id == GUI_ID_VAL3)
{
IDChar = 11;
stringw temp = L" ";
temp += IDChar;
env->addStaticText(temp.c_str(),rect<s32>(380,700,670,750),false);
}
return true;
}
return false;
}
return false;
}
private:
int IDChar, IDperso;
SAppContext & Context;
};
class character
{
public:
character(IrrlichtDevice* Device);
~character();
char draw();
int IDChar, IDperso;
int fonction() { return IDChar; }
private:
IrrlichtDevice* device;
IVideoDriver *driver;
ISceneManager *scenegraph;
IGUIEnvironment *env;
IGUIImage *img;
IAnimatedMesh* modele;
IAnimatedMeshSceneNode* Nmodele;
IAnimatedMesh* modele2;
IAnimatedMeshSceneNode* Nmodele2;
IGUIEnvironment *gui;
};
#endif
character.cpp
Code: Select all
#include "character.h"
#include <iostream>
#include <fstream>
character::character(IrrlichtDevice* Device)
{
device = Device;
driver = device->getVideoDriver ();
scenegraph = device->getSceneManager ();
gui = scenegraph->getGUIEnvironment();
env = device->getGUIEnvironment();
scenegraph->addCameraSceneNode (0, core::vector3df (0,0,0), core::vector3df (50,0,0));
IGUIImage *img = env->addImage(rect<s32>(0,0,1024,768));
img->setImage(driver->getTexture("media/cadre.jpg"));
int IDperso = 11;
// Perso 1
modele2 = scenegraph->getMesh("persos/11.x");
Nmodele2 = scenegraph->addAnimatedMeshSceneNode(modele2);
Nmodele2->setPosition(core::vector3df(150,-30,70));
Nmodele2->setRotation(core::vector3df(0,80,0));
Nmodele2->setMaterialFlag(video::EMF_LIGHTING, false);
Nmodele2->setFrameLoop(0,0);
Nmodele2->setMaterialTexture( 0, driver->getTexture("persos/dwarf.jpg") );
// Perso 2
modele = scenegraph->getMesh("persos/test/player.x");
Nmodele = scenegraph->addAnimatedMeshSceneNode(modele);
Nmodele->setPosition(core::vector3df(10.5,0.5,-0.5));
Nmodele->setRotation(core::vector3df(0,-90,0));
Nmodele->setMaterialFlag(video::EMF_LIGHTING, false);
env->addButton(core::rect<s32>(190,600,330,650), 0, GUI_ID_VAL1, L"Selection");
env->addButton(core::rect<s32>(460,600,600,650), 0, GUI_ID_VAL2, L"Selection");
env->addButton(core::rect<s32>(740,600,880,650), 0, GUI_ID_VAL3, L"Selection");
IGUIStaticText* choixperso = env->addStaticText(L"Choix du personnage",rect<s32>(380,700,670,750),false);
SAppContext context;
context.device = device;
MyEventReceiver receiver(context);
device->setEventReceiver(&receiver);
}
character::~character()
{
scenegraph->clear();
env->clear();
gui->clear();
driver->removeAllTextures();
}
char character::draw()
{
}
Thanks for your help. It do like i want on a classic program but when i want introduce it in mine, big crash without compiler error.
help me please