entre Desarrolladores

Recibe ayuda de expertos

Registrate y pregunta

Es gratis y fácil

Recibe respuestas

Respuestas, votos y comentarios

Vota y selecciona respuestas

Recibe puntos, vota y da la solución

Pregunta

1voto

¿Para poner escenario en libgdx?

No me sale la imagen y no se ya que hago mal...

Esto me sale en LogCat :

FATAL EXCEPTION: GLThread 51
Process: com.videojuego, PID: 924
java.lang.NullPointerException
at com.videojuego.Plataforma.<init>(Plataforma.java:30)
at com.videojuego.MyGame.create(MyGame.java:30)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:209)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Este es mi codigo:

public class MyGame extends Game implements ApplicationListener{

    public SpriteBatch Batcher;
    public World mundo; 
    public Body pisoCuerpo;
    public float PX_TO_METERS = 80f; 
    public Plataforma piso;
    public Sprite piso1;

    @Override
    public void create() { 
        Batcher = new SpriteBatch();
        mundo = new World(new Vector2(0,-98f),true);
        piso = new Plataforma(this,250,250);
        piso1 = new Sprite(new Texture(Gdx.files.internal("plataforma1.png")));
        piso1.setSize(Gdx.graphics.getWidth(),30);

        this.setScreen(new PantallaJuego(this));

--------- Otro:

public class PantallaJuego implements Screen {

    public SpriteBatch Batcher;
    public World mundo;
    public Body pisoCuerpo; 
    public Plataforma piso;
    protected Texture texture; 
    public Sprite piso1;

    MyGame juego;

    public PantallaJuego(MyGame Game) {
    this.juego = Game;

    }

    @Override
    public void render(float delta) { 

        Gdx.gl.glClearColor(0,0,0,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        mundo.step(1f/60f,6,2);

        Batcher.begin();
        piso1.draw(Batcher);
        Batcher.end();

    }

    @Override
    public void resize(int width, int height) {
        // TODO Auto-generated method stub

    }

    @Override
    public void show() { 
        // TODO Auto-generated method stub

        piso1 = new Sprite(new Texture(Gdx.files.internal("plataforma1.png")));
        Batcher = new SpriteBatch();

    }

    @Override
    public void hide() {
        // TODO Auto-generated method stub

    }

    @Override
    public void pause() {
        // TODO Auto-generated method stub

    }

    @Override
    public void resume() {
        // TODO Auto-generated method stub

    }

    @Override
    public void dispose() {

        Batcher.dispose();
        texture.dispose();

    }

}

Y la clase que cree para la Plataforma:

public class Plataforma {

    protected Body pisoCuerpo;
    protected Texture texture;
    protected Sprite plataforma1; //
    public MyGame game;
    protected World mundo;
    protected Sprite piso1;
    public float PX_TO_METERS = 80f;

    public Plataforma(MyGame Game,float x,float y) {

        this.game = Game;

        piso1 = new Sprite(new Texture(Gdx.files.internal("plataforma1.png")));
        plataforma1.setPosition(x,y); 

        setFloorBody();

    }

          private void setFloorBody() {

        BodyDef bodyDef = new BodyDef(); 
        bodyDef.type = BodyDef.BodyType.StaticBody;
        bodyDef.position.set(0,0); // posicion del objeto en el mundo (x,y)

        pisoCuerpo = this.game.mundo.createBody(bodyDef); 

        PolygonShape shape = new PolygonShape(); 

        shape.setAsBox(   
        piso1.getWidth()/2 / PX_TO_METERS,
        piso1.getHeight()/2 / PX_TO_METERS);

        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = shape;
        fixtureDef.density =1f;

        pisoCuerpo.createFixture(fixtureDef);

        shape.dispose();    

}
       public void draw(SpriteBatch Batcher){

           piso1.draw(Batcher);
       }

       }

0voto

white comentado

No entiendo, escenario es una imagen que representa el fondo de tu juego? cual es el rol de esta imagen?

0voto

carla_Maria comentado

Para que el personaje se ponga encima una estructura(plataforma) yo quiero poner una mía que he hecho

Por favor, accede o regístrate para responder a esta pregunta.

Otras Preguntas y Respuestas


...

Bienvenido a entre Desarrolladores, donde puedes realizar preguntas y recibir respuestas de otros miembros de la comunidad.

Conecta