IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SDL Discussion :

IMG_Load ne charge pas toutes les images


Sujet :

SDL

  1. #1
    Membre actif
    Homme Profil pro
    Analyste/développeur Java EE
    Inscrit en
    Janvier 2005
    Messages
    376
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste/développeur Java EE

    Informations forums :
    Inscription : Janvier 2005
    Messages : 376
    Points : 271
    Points
    271
    Par défaut IMG_Load ne charge pas toutes les images
    Bonjour,
    je suis en train de coder un pacman avec SDL, je me suis vite retrouver avec du code trop long et j'ai décidé de le couper en fonctions et fichiers.

    J'ai créé une fonction qui devrait charger toutes mes images (cette fonction se trouve dans chargement.c):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    void chargementSprites(SDL_Surface *pacman[5], SDL_Surface *fantome[6][4],SDL_Surface *mur, SDL_Surface *pastille, SDL_Surface *special){
      pacman[BAS] = IMG_Load("img/pacman_bas.png");
      pacman[GAUCHE] = IMG_Load("img/pacman_gauche.png");
      pacman[HAUT] = IMG_Load("img/pacman_haut.png");
      pacman[DROITE] = IMG_Load("img/pacman_droite.png"); 
      pacman[MORT] = IMG_Load("img/pacman_mort.png");
      ...
      ...
      mur = IMG_Load("img/mur.png");
      pastille = IMG_Load("img/pastille.png");
      special = IMG_Load("img/special.png");
    }
    Les surfaces sont déclarées en tant que variables globales dans jeu.c et je fais l'appel comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    chargementSprites(pacman,fantome,mur,pastille,special);
    Le problème: il me charge les pacmans, les fantômes mais pas les décors... Il le faisait bien avant mais là, niet il veut pas...

    A quoi pourrait être du ce problème et comment le solutionner?

    Merci d'avance
    Utilisez les balises "Code" (alt+c).
    Nous avons répondu à votre question? Pensez au tag

    Le "lol" est aux boulets ce que le ";" est aux programmeurs

  2. #2
    Membre habitué Avatar de razmott
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    133
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 133
    Points : 142
    Points
    142
    Par défaut
    Salut !

    Le problème: il me charge les pacmans, les fantômes mais pas les décors
    C'est dû une simple erreur dans ton prototype de fonction :
    lorsque l'on passe un argument à une fonction, il ne peut être modifié. On utilise donc des pointeurs. IMG_Load te renvoie un nouveau pointeur. Dans le cas des tableaux, pas de problème, ce sont des "pointeurs heut niveau". Pour les autres, les modifications ne passent pas et tu ne peux pas accéder à tes images.

    Cela peut paraître un paradoxe, vu que la fonction reçoit des pointeurs. Mais ce sont les pointeurs que IMG_Load modifie et non leur contenu.

    Deux solutions donc, soit tu utilises des pointeurs de pointeur(pas très jolie mais efficace) :

    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
     
    void chargementSprites(SDL_Surface *pacman[5], SDL_Surface *fantome[6][4],SDL_Surface **mur, SDL_Surface **pastille, SDL_Surface **special){
      pacman[BAS] = IMG_Load("img/pacman_bas.png");
      pacman[GAUCHE] = IMG_Load("img/pacman_gauche.png");
      pacman[HAUT] = IMG_Load("img/pacman_haut.png");
      pacman[DROITE] = IMG_Load("img/pacman_droite.png"); 
      pacman[MORT] = IMG_Load("img/pacman_mort.png");
      ...
      ...
      *mur = IMG_Load("img/mur.png");
      *pastille = IMG_Load("img/pastille.png");
      *special = IMG_Load("img/special.png");
    }
     
    // Appel à la fonction
    chargementSprites(pacman,fantome,&mur,&pastille,&special);
    Soit tu utilises des références :
    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
     
    void chargementSprites(SDL_Surface *pacman[5], SDL_Surface *fantome[6][4],SDL_Surface *&mur, SDL_Surface *&pastille, SDL_Surface *&special){
      pacman[BAS] = IMG_Load("img/pacman_bas.png");
      pacman[GAUCHE] = IMG_Load("img/pacman_gauche.png");
      pacman[HAUT] = IMG_Load("img/pacman_haut.png");
      pacman[DROITE] = IMG_Load("img/pacman_droite.png"); 
      pacman[MORT] = IMG_Load("img/pacman_mort.png");
      ...
      ...
      mur = IMG_Load("img/mur.png");
      pastille = IMG_Load("img/pastille.png");
      special = IMG_Load("img/special.png");
    }
     
    // Appel à la fonction
    chargementSprites(pacman,fantome,mur,pastille,special);
    Voilà !

    Bon coding !

    @+
    Mieux vaut prévoir que patcher.

  3. #3
    Membre actif
    Homme Profil pro
    Analyste/développeur Java EE
    Inscrit en
    Janvier 2005
    Messages
    376
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste/développeur Java EE

    Informations forums :
    Inscription : Janvier 2005
    Messages : 376
    Points : 271
    Points
    271
    Par défaut
    Un grand merci à toi, j'aurai jamais trouvé.

    Ca fonctionne au poil maintenant.
    Utilisez les balises "Code" (alt+c).
    Nous avons répondu à votre question? Pensez au tag

    Le "lol" est aux boulets ce que le ";" est aux programmeurs

  4. #4
    Membre confirmé
    Avatar de Mindiell
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    735
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 735
    Points : 546
    Points
    546
    Par défaut
    Comme quoi, une serie de test après chaque chargement t'aurais permis de voir que les images, elles, étaient bien chargées pourtant...
    Mindiell
    "Souvent, femme barrit" - Elephant man

  5. #5
    Membre actif
    Homme Profil pro
    Analyste/développeur Java EE
    Inscrit en
    Janvier 2005
    Messages
    376
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste/développeur Java EE

    Informations forums :
    Inscription : Janvier 2005
    Messages : 376
    Points : 271
    Points
    271
    Par défaut
    C'est-à-dire? Tester si le retour est différent de NULL?

    P.S: Comment peut-on installer les pages man de SDL? Je suis sur Ubuntu et je n'y ai pas accès sans internet
    Utilisez les balises "Code" (alt+c).
    Nous avons répondu à votre question? Pensez au tag

    Le "lol" est aux boulets ce que le ";" est aux programmeurs

  6. #6
    Membre confirmé
    Avatar de Mindiell
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    735
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 735
    Points : 546
    Points
    546
    Par défaut
    exactement. Mes fonctions de chargement de sprites me sortent tout plein d'nifos, une fois le sprite chargé :
    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
    Picture loaded successfully from images/fish.bmp
    frame number 0 get x=0 and y=0 with an height=54 and a width=21 loaded.
    frame number 1 get x=21 and y=0 with an height=54 and a width=21 loaded.
    frame number 2 get x=42 and y=0 with an height=54 and a width=21 loaded.
    frame number 3 get x=63 and y=0 with an height=54 and a width=21 loaded.
    frame number 4 get x=84 and y=0 with an height=54 and a width=21 loaded.
    frame number 5 get x=105 and y=0 with an height=54 and a width=21 loaded.
    frame number 6 get x=126 and y=0 with an height=54 and a width=21 loaded.
    frame number 7 get x=147 and y=0 with an height=54 and a width=21 loaded.
    frame number 8 get x=168 and y=0 with an height=54 and a width=21 loaded.
    frame number 9 get x=189 and y=0 with an height=54 and a width=21 loaded.
    frame number 10 get x=210 and y=0 with an height=54 and a width=21 loaded.
    frame number 11 get x=231 and y=0 with an height=54 and a width=21 loaded.
    frame number 12 get x=252 and y=0 with an height=54 and a width=21 loaded.
    Picture loaded successfully from images/coin.bmp
    frame number 0 get x=0 and y=0 with an height=16 and a width=16 loaded.
    frame number 1 get x=16 and y=0 with an height=16 and a width=16 loaded.
    frame number 2 get x=32 and y=0 with an height=16 and a width=16 loaded.
    frame number 3 get x=48 and y=0 with an height=16 and a width=16 loaded.
    frame number 4 get x=64 and y=0 with an height=16 and a width=16 loaded.
    frame number 5 get x=80 and y=0 with an height=16 and a width=16 loaded.
    frame number 6 get x=96 and y=0 with an height=16 and a width=16 loaded.
    frame number 7 get x=112 and y=0 with an height=16 and a width=16 loaded.
    Picture loaded successfully from images/truc.bmp
    frame number 0 get x=0 and y=0 with an height=30 and a width=36 loaded.
    frame number 1 get x=36 and y=0 with an height=30 and a width=36 loaded.
    frame number 2 get x=72 and y=0 with an height=30 and a width=36 loaded.
    frame number 3 get x=108 and y=0 with an height=30 and a width=36 loaded.
    frame number 4 get x=144 and y=0 with an height=30 and a width=36 loaded.
    frame number 5 get x=180 and y=0 with an height=30 and a width=36 loaded.
    Color 16711935 transparent.
    Color 16711935 transparent.
    Color 16711935 transparent.
    Sprite 0 at (609,100) with speed of (0,-1)
    Avec ce genre de retour dans un fichier log, tu peux bien étudier ce qui se passe au niveau de ton prog et résoudre tes problèmes beaucoup plus vite. Les retours de fonctions ne sont pas là pour rien
    Mindiell
    "Souvent, femme barrit" - Elephant man

  7. #7
    Expert éminent sénior

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Points : 11 877
    Points
    11 877
    Par défaut
    Citation Envoyé par v4np13
    C'est-à-dire? Tester si le retour est différent de NULL?

    P.S: Comment peut-on installer les pages man de SDL? Je suis sur Ubuntu et je n'y ai pas accès sans internet
    http://www.libsdl.org/archives/sdldoc-man3.tar.gz

    ensuite tu fais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    tar xvfz sdldoc-man3.tar.gz
    sudo cp -r man3 /usr/share/man/
    Et tu devrais avoir accès aux pages de la SDL. Par contre, je ne sais pas où se trouve les pages man de la SDL_image.

    Jc

  8. #8
    Membre actif
    Homme Profil pro
    Analyste/développeur Java EE
    Inscrit en
    Janvier 2005
    Messages
    376
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste/développeur Java EE

    Informations forums :
    Inscription : Janvier 2005
    Messages : 376
    Points : 271
    Points
    271
    Par défaut
    Merci pour votre aide
    Utilisez les balises "Code" (alt+c).
    Nous avons répondu à votre question? Pensez au tag

    Le "lol" est aux boulets ce que le ";" est aux programmeurs

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [CS3] Ne pas charger toutes les images.
    Par yann123456 dans le forum Dreamweaver
    Réponses: 1
    Dernier message: 03/07/2009, 16h42
  2. Réponses: 2
    Dernier message: 04/10/2007, 13h42
  3. Ne pas rafraichir les images avec PHP
    Par tornaod dans le forum Langage
    Réponses: 4
    Dernier message: 07/12/2005, 22h44
  4. [Performance] - Blob ou pas pour les images d'un site ?
    Par ShinJava dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 04/07/2005, 17h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo