Bonjour a tous, voila j'ai un petit souci, dans l'un de mes methodes, je charge la fenetre principale, je colle une image, et la mystere, a l'execution, la fenetre s'affiche bien avec l'image mais ne reste visible que pendant 1/10 de seconde ^^, sachant que deriere je recupere un evenement un mode blocant (WaitEven)
la fenetre devrais rester visible, pour info lorsque la fenetre se ferme , sa coupe le prog, je suppose donc qu'une erreur SDL se produit...
voila mon code pour la class :
BONHOMME::BONHOMME(){ //CONSTRUCTEUR
SDL_Init(SDL_INIT_VIDEO);
largeur_fenetre = 320 ;
longueur_fenetre = 640 ;
profondeur_fenetre = 32;
titre_fenetre = "TITRE PAR DEFAULT";
chemin_image = "defaut.bmp";
//image = SDL_LoadBMP(chemin_image.c_str());
transparence_image.rouge = 0;
transparence_image.vert = 0;
transparence_image.bleu = 0;
position_image.x = 0;
position_image.y = 0;
}
BONHOMME::~BONHOMME(){
SDL_FreeSurface(fenetre);
SDL_FreeSurface(image);
SDL_Quit();
}
void BONHOMME::init_affichage(){
fenetre = SDL_SetVideoMode(longueur_fenetre, largeur_fenetre, profondeur_fenetre, SDL_HWSURFACE);
SDL_WM_SetCaption(titre_fenetre.c_str(), NULL);
image = SDL_LoadBMP(chemin_image.c_str());
SDL_SetColorKey(image, SDL_SRCCOLORKEY, SDL_MapRGB (image->format, transparence_image.rouge, transparence_image.vert, transparence_image.bleu)); // rend player 1 transparent
SDL_BlitSurface(image, NULL, fenetre, &position_image); //colle image dans la fenetre
SDL_Flip(fenetre); // C'EST ICI QUE SA MERDE !!!!!!!!!!!!!!!!!!}
void BONHOMME::new_image(std::string value){ // DEFINIT L'IMAGE A CHARGER
chemin_image.erase();
chemin_image = value;
//image = SDL_LoadBMP(chemin_image.c_str());
}
void BONHOMME::new_imageposition(int x, int y){ // DEFINIT LA POSITION DE L'IMAGE
position_image.x = x;
position_image.y = y;
}
void BONHOMME::new_title(std::string value){ // DEFINIT LE TITRE DE LA FENETRE
titre_fenetre.erase();
titre_fenetre = value;
}
void BONHOMME::new_imagecolor(int value_rouge, int value_vert, int value_bleu){ // DEFINITION DES COULEURS A RENDRE TRANSPARENTE
transparence_image.rouge = value_rouge;
transparence_image.vert = value_vert;
transparence_image.bleu = value_bleu;
}
void BONHOMME::new_taillefenetre(int longueur, int largeur, int profondeur){ // DEFINIT LA TAILLE DE LA FENETRE
largeur_fenetre = largeur;
longueur_fenetre = longueur;
profondeur_fenetre = profondeur;
}
void BONHOMME::evenement_blocant(){
SDL_WaitEvent(&my_evenement);
}
void BONHOMME::evenement_passif(){
SDL_PollEvent (&my_evenement);
}
MA DECLARATION DE CLASS DU FICHIER .H
#ifndef DEF_BONHOMME
#define DEF_BONHOMME
#include <SDL/SDL.h>
#include <string>
class BONHOMME
{
public:
BONHOMME();
~BONHOMME();
void init_affichage(); // AFFICHE
void new_image(std::string value); // DEFINIT UNE NOUVELLE IMAGE A CHARGER
void new_imageposition(int x, int y); // DEFINIT LA POSITION DE L'IMAGE
void new_title(std::string value); // DEFINIT UN NOUVEAU TITRE A LA FENETRE
void new_imagecolor(int value_rouge, int value_vert, int value_bleu); // DEFINIT LA COULEUR DE L'IMAGE A RENDRE TRANSPARENTE
void new_taillefenetre(int largeur, int longueur, int profondeur); // DEINIT LA TAILLE DE LA FENETRE
void evenement_passif();
void evenement_blocant();
SDL_Event my_evenement;
private:
SDL_Surface *fenetre;
SDL_Surface *image;
SDL_Rect position_image;
int largeur_fenetre;
int longueur_fenetre;
int profondeur_fenetre;
std::string titre_fenetre;
std::string chemin_image;
struct {
int rouge;
int vert;
int bleu;
}transparence_image;
};
#endif
**********************
dans tous les cas merci d'avance a tous ceux qui se pencheront sur mon probleme ;-)
mon mail : erwannludovic@free.fr