CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Probleme d'affichage avec las SDL[c++]

pandamark
pandamark
Niveau 6
01 septembre 2005 à 17:35:10

:hello:
J´ai des probleme avec la SDL d´affichage l´image va du noir à l´image(elle clignote en quelque sorte). Je cherche depuis quelque heure mais je trouve rien voici le code:

Main.cpp:

  1. include "Moteur.h"

extern int xsouris,xrelsouris,yrelsouris,ysouris;
extern char boutons[3];
extern char key[400];
ofstream test;
Map *Map1;

void Init()
{
GameEngine("Ground Fighters", false);
Map1=new
Map("Source/Data/Map/1.txt","Source/Data/ChipSet.b
mp");
}

void Loop()
{

}

void Paint()
{

Map1->Draw();
}

bool Endloop()
{
test.open("test.txt");
test << "Checking if we pass the Enter phase." ;
if(key[SDLK_RETURN]){return true;}
test << "Passed it. Got another probleme." ;

return false;
}

Moteur.cpp:

  1. include "Moteur.h"
  2. include <SDL/SDL.h>

SDL_Surface *Screen;
ofstream Error;
int xsouris=0,xrelsouris=0,yrelsouris=0,ysouris=0;
char boutons[3]={0,0,0};
char key[400];

//--Class GameEngine--//

GameEngine::GameEngine(char *cName, bool bFullScreen)
{
Error.open("Error.txt");
if(SDL_Init(SDL_INIT_VIDEO)==-1)
{
Error << "Enable to init sdl : " << SDL_GetError() ;
Error.close();
}
//atexit(SDL_Quit);

if(bFullScreen){Screen=SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);}
else{Screen=SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);}

if(Screen==NULL)
{
Error << "Enable to make window : " << SDL_GetError() ;
Error.close();
}

SDL_WM_SetCaption(cName, NULL);
}

//--Class Sprite--//

Sprite::Sprite(char *cDestination, int iX, int iY)
{
Image=LoadBMP(cDestination);
Rect.x=iX;
Rect.y=iY;
}

void Sprite::Surface(int iSrcX, int iSrcY, int iSrcW, int iSrcH)
{
Src.x=iSrcX;
Src.y=iSrcY;
Src.w=iSrcW;
Src.h=iSrcH;
}

void Sprite::Move(int iMoveX, int iMoveY)
{
Rect.x=Rect.x+iMoveX;
Rect.y=Rect.y+iMoveY;
}

void Sprite::Draw()
{
SDL_BlitSurface(Image, &Src, Screen, &Rect);
}

Map::Map(char *Mapname, char *Image)
{
short y, x;

MapName=Mapname;

map.open(MapName);

for(y=0;y<30;y++)
{
for(x=0;x<40;x++)
{
map >> MapTile[x][y];
}
}

for(y=0;y<30;y++)
{
for(x=0;x<40;x++)
{
tile[x][y]=new Sprite(Image, x*16, y*16);

surface.x=(MapTile[x][y]-1)*16;
surface.y=0;

tile[x][y]->Surface(surface.x, surface.y, 16, 16);
tile[x][y]->Draw();
}
}
}

void Map::Draw()
{
short y, x;

for(y=0;y<30;y++)
{
for(x=0;x<40;x++)
{
surface.x=MapTile[x][y]*16;
surface.y=MapTile[x][y]*16;

tile[x][y]->Surface(surface.x, surface.y, 16, 16); tile[x][y]->Draw();
}
}
}

//--Fonctions--//

SDL_Surface *LoadBMP(const char *filename)//Du tutorial de [DmX]
{
SDL_Surface *temp, *image;
temp=SDL_LoadBMP(filename);
image=SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
if(image==NULL)
{
Error << "Can´t load image\n";
}
return image;
}

void UpdateEvents()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
key[event.key.keysym.sym]=1;
break;
case SDL_KEYUP:
key[event.key.keysym.sym]=0;
break;
case SDL_MOUSEMOTION:
xsouris=event.motion.x;
ysouris=event.motion.y;
xrelsouris=event.motion.xrel;
yrelsouris=event.motion.yrel;
break;
case SDL_MOUSEBUTTONDOWN:
boutons[event.button.button-1]=1;
break;
case SDL_MOUSEBUTTONUP:
boutons[event.button.button-1]=0;
break;
}
}
}

int main(int argc, char **argv)
{
long Framedelay=50;
bool StopLoop=false;

while(!StopLoop)
{
Init();
if(SDL_GetTicks()>=Framedelay)
{
Loop();
Framedelay=SDL_GetTicks()+50;
Paint();
}

UpdateEvents();
SDL_Flip(Screen);

StopLoop=Endloop();
}
return 0;
}

Moteur.h:

  1. include <SDL/SDL.h>

//#include <SDl/SDL_tff.h> //-Not used until in version 1.0.1-
//#include <fmod/fmod.h> //-Not used until in version 1.0.1-

  1. include <fstream>

class GameEngine
{
private:
short iFrameSet;//-Not used until in Versions 1.0.2-
short iWindowX;//-Not used until in Versions 1.0.2-
short iWindowY;//-Not used until in Versions 1.0.2-
public:
GameEngine(char *cName, bool bFullScreen);
};

class Sprite
{
private:
SDL_Surface *Image;
SDL_Rect Rect, Src;
public:
Sprite(char *cDestination, int iX, int iY);
void Surface(int iSrcX, int iSrcY, int iSrcW, int iSrcH);
void Move(int iMoveX, int iMoveY);
void Draw();
};

class Map
{
private:
int MapSize[2];//-Not used until in Versions 1.0.2-
int MapTile[40][30];
SDL_Rect surface;
Sprite *tile[40][30];
char *MapName;
ifstream map;
public:
Map(char *Mapname, char *Image);
void Draw();
void ChangeTile(short x, short y, short TileX, short TileY);//-Not used until in Versions 1.0.3-
};

void Init();
void Loop();
void Paint();
void UpdateEvents();
bool Endloop();

SDL_Surface *LoadBMP(const char *filename);

JeanYvesYves
JeanYvesYves
Niveau 10
01 septembre 2005 à 17:43:13

sors le init() et le endloop de ton while principal du main...

Reinitialiser tuot a chaque frame est ... comment dire.... violent !

alex6891
alex6891
Niveau 10
01 septembre 2005 à 18:25:16

En effet ça doit juste venir d´un problème de "bouclage intenpestif et ultra-violent" comme l´a très bien décrit JYY :sournois:

pandamark
pandamark
Niveau 6
02 septembre 2005 à 08:06:07

Merci beaucoup.Ca ce voit que je suis pas assez logique.On n´initialise pas deux fois la meme chose :honte: .Parcontre ilf aut juste enlever le endloop() pour moi.

Sous forums
  • Aide à l'achat Mac
  • Création de Jeux
  • Linux
  • Création de sites web
  • Programmation
  • Internet
  • Steam Deck
  • Macintosh
  • Hardware
La vidéo du moment