Salut, j'ai un petit problème avec mon programme car il s'ouvre et se ferme en un éclair. Pour le moment j'essais de combiner SDL et POO, donc de n'afficher qu'une image:
main.cpp:
Personnage.h:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #include <stdlib.h> #include <stdio.h> #include <time.h> #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include "Personnage.h" int main(int argc, char *argv[]) { //--------------------------------------------------------------------- Personnage *perso; SDL_Surface *ecran = NULL; SDL_Rect positionFond; SDL_Event event; bool continuer = true; positionFond.x = 0; positionFond.y = 0; SDL_Init(SDL_INIT_VIDEO); SDL_WM_SetIcon(IMG_Load("perso.png"), NULL); ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); SDL_WM_SetCaption("TeeworldsLike", NULL); //--------------------------------------------------------------------- perso->afficherPerso(ecran); SDL_Flip(ecran); while (continuer) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: continuer = false; } SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); perso->afficherPerso(ecran); SDL_Flip(ecran); } SDL_FreeSurface(ecran); SDL_Quit(); return EXIT_SUCCESS; }
Personnage.cpp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #ifndef DEF_PERSONNAGE #define DEF_PERSONNAGE #include <SDL/SDL.h> #include <SDL/SDL_image.h> class Personnage { public: Personnage(); void setCoordAffiche(int x, int y); void afficherPerso(SDL_Surface* ecran); private: SDL_Surface* imagePerso; SDL_Rect positionPerso; }; #endif
Aprés quelques test, je conclu que le problème vient de ma fonction afficherPerso. Le programme ne me donne aucunes erreurs.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include "Personnage.h" Personnage::Personnage() { imagePerso = new SDL_Surface; imagePerso = IMG_Load("perso.png"); positionPerso.x = 500; positionPerso.y = 500; } void Personnage::setCoordAffiche(int x, int y) { positionPerso.x = x; positionPerso.y = y; } void Personnage::afficherPerso(SDL_Surface* ecran) { SDL_BlitSurface(imagePerso, NULL, ecran, &positionPerso); }
Je ne vois donc pas d'ou vient le problème; merci de m'aider.![]()
Partager