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

Android Discussion :

[libgdx] Débutant : problème d'affichage et de compréhension de code


Sujet :

Android

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2013
    Messages : 1
    Points : 1
    Points
    1
    Par défaut [libgdx] Débutant : problème d'affichage et de compréhension de code
    Bonjour,

    Hier en TP j'ai commencé à apprendre à utiliser les fonctions de bases de libgdx comme create(), render(), resize(int, int), pause(), resume(), et dispose() afin de créer un jeu Pacman au bout d'un semestre. Cependant, étant débutant j'aurais besoin qu'on m'explique clairement à quoi sert chaque fonction, qui appelle qui où et quand, etc... Voici le code des 7 classes présentes (la plupart des classes ne font que quelques lignes et encore, des fonctions vides) :

    MainActivity.java :
    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
    package fr.univ_lorraine;
    import android.os.Bundle;
     
    import com.badlogic.gdx.backends.android.AndroidApplication;
    import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
     
    import fr.univ_lorraine.pacman.PacmanGame;
     
    public class MainActivity extends AndroidApplication
    {
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
     
            AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
            cfg.useGL20 = true;
     
            initialize(new PacmanGame(), cfg);
        }
    }
    PacmanGame.java :
    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
    package fr.univ_lorraine.pacman;
    import com.badlogic.gdx.Game;
     
    import fr.univ_lorraine.pacman.model.World;
    import fr.univ_lorraine.pacman.view.GameScreen;
     
    public class PacmanGame extends Game
    {
    	private World world;
    	private GameScreen gamescreen;
     
    	public void create()
    	{
    		world = new World();
    		gamescreen = new GameScreen(world);
    		this.setScreen(gamescreen);
    	}
     
    	public void render()
    	{
     
    	}
     
    	public void resize(int width, int height)
    	{
     
    	}
     
    	public void pause()
    	{
     
    	}
     
    	public void resume()
    	{
     
    	}
     
    	public void dispose()
    	{
     
    	}
    }
    World.java :
    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    package fr.univ_lorraine.pacman.model;
     
    public class World
    {
    	private int nbL, nbC;
    	private Pacman pacman;
    	private int maze[][] = 
    		{
    		{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    		{1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    		{1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1},
    		{1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1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1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1},
    		{1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
    		{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
    		};
     
    	public World()
    	{
    		nbL = 28;
    		nbC = 31;
    		pacman = new Pacman(48, 48); // positions initiales (taille bloc)
    	}
     
    	public int getNbL()
    	{
    		return nbL;
    	}
     
    	public int getNbC()
    	{
    		return nbC;
    	}
     
    	public Pacman getPacman()
    	{
    		return pacman;
    	}
     
    	public int getMaze(int i, int j)
    	{
    		return maze[i][j];
    	}
     
    	public boolean estUnBlock(int i, int j)
    	{
    		return maze[i][j] == 1;
    	}
    }
    GameScreen.java :
    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    package fr.univ_lorraine.pacman.view;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.Screen;
    import com.badlogic.gdx.graphics.GL10;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import fr.univ_lorraine.pacman.model.Block;
    import fr.univ_lorraine.pacman.model.World;
     
    public class GameScreen implements Screen
    {
    	private World world;
    	private SpriteBatch spriteBatch;
     
    	public GameScreen(World world)
    	{
    		this.world = world;
    	}
     
    	public void create()
    	{
    		this.show();
    	}
     
    	public void render(float delta)
    	{
    		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    		Block tmp = new Block(0, 0);
     
    		spriteBatch.begin();
     
    		for(int i = 0; i < world.getNbL(); i++)
    		{
            	for(int j = 0; j < world.getNbC(); j++)
            	{
            		if(world.estUnBlock(i, j))
            		{
            			spriteBatch.draw(tmp.getTexture(), i * 48, j * 48, 48, 48);  // positions des blocs * taille bloc
            		}
            	}
            }
     
            spriteBatch.draw(world.getPacman().getTexture(), world.getPacman().getX(), world.getPacman().getY(), 13, 13);
    		spriteBatch.end();
    	}
     
    	public void resize(int width, int height)
    	{
     
    	}
     
    	public void pause()
    	{
     
    	}
     
    	public void resume()
    	{
     
    	}
     
    	public void dispose()
    	{
     
    	}
     
    	public void show()
    	{
    		spriteBatch = new SpriteBatch();
    	}
     
    	public void hide()
    	{
     
    	}
    }
    GameElement.java :
    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    package fr.univ_lorraine.pacman.model;
    import com.badlogic.gdx.graphics.Texture;
     
    public class GameElement
    {
    	private int x, y;
    	protected int largeur, hauteur;
    	protected Texture texture;
     
    	public GameElement(int x, int y)
    	{
    		this.x = x;
    		this.y = y;
    	}
     
    	public int getX()
    	{
    		return x;
    	}
     
    	public int getY()
    	{
    		return y;
    	}
     
    	public int getLargeur()
    	{
    		return largeur;
    	}
     
    	public int getHauteur()
    	{
    		return hauteur;
    	}
     
    	public Texture getTexture()
    	{
    		return texture;
    	}
     
    	public void setX(int nouveauX)
    	{
    		x = nouveauX;
    	}
     
    	public void setY(int nouveauY)
    	{
    		y = nouveauY;
    	}
     
    	public void setLargeur(int nouvelleLargeur)
    	{
    		largeur = nouvelleLargeur;
    	}
     
    	public void setHauteur(int nouvelleHauteur)
    	{
    		hauteur = nouvelleHauteur;
    	}
     
    	public void setTexture(Texture nouvelleTexture)
    	{
    		texture = nouvelleTexture;
    	}
    }
    Pacman.java :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package fr.univ_lorraine.pacman.model;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.Texture;
     
    public class Pacman extends GameElement
    {
    	public Pacman(int x, int y)
    	{
    		super(x, y);
    		largeur = 13;
    		hauteur = 13;
    		texture = new Texture(Gdx.files.internal("data/pacmanLeft.png"));
    	}
    }
    Block.java :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package fr.univ_lorraine.pacman.model;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.Texture;
     
    public class Block extends GameElement
    {	
    	public Block(int x, int y)
    	{
    		super(x, y);
    		largeur = 48;
    		hauteur = 48;
    		texture = new Texture(Gdx.files.internal("data/bloc.png"));
    	}
    }


    Mon problème se situerait plutôt dans les classes censées afficher les objets (GameScreen.java et PacmanGame.java). J'ai essayé de coder assez clairement mais en exécutant j'obtiens un écran noir alors que je suis censé obtenir un labyrinthe (voire maze[][] de World), ou même de simples carrés, histoire de ne pas avoir un écran noir... Quelqu'un pourrait m'aider à comprendre ce qui ne va pas ?

    Merci d'avance.

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Salut,

    Je pense que tu auras plus de réponse dans la section Jeu qu'ici .
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

Discussions similaires

  1. [Free Pascal] [Débutant] Problème d'affichage : ligne indélébile
    Par Redoxe dans le forum Free Pascal
    Réponses: 2
    Dernier message: 01/07/2009, 13h57
  2. [JavaFX] (Débutant) Problème d'affichage d'un menu
    Par mikl_apo dans le forum JavaFX
    Réponses: 3
    Dernier message: 31/03/2009, 22h25
  3. Réponses: 7
    Dernier message: 25/03/2009, 09h22
  4. [SQL] débutante: Problème d'affichage de requete
    Par katie dans le forum PHP & Base de données
    Réponses: 25
    Dernier message: 20/09/2006, 23h21
  5. [débutant]problèmes d'affichage dans un tableau
    Par Hastur dans le forum Balisage (X)HTML et validation W3C
    Réponses: 12
    Dernier message: 16/08/2005, 13h00

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