eDac
eDac

Reputation: 11

LibGDX Sprite Screens not loading graphics, or loading up screens

I have this issue in my LibGDX project, I essentially can't load up my gamescreen, I am following a YouTube tutorial (link to particular tutorial I'm on: https://www.youtube.com/watch?v=LSblkR4K1LU), and I have found that my sprite that is supposed to go on my screen, just it won't load up at all, it just opens, closes then pops this up: http://puu.sh/coxUv/d877d08a83.png, I will admit the only thing I have changed from the video was this:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();    

I changed GL10.GL_COLOR_BUFFER_BIT (that was in the video), to GL20.GL_COLOR_BUFFER_BIT, because it gave me an error: GL10 cannot be resolved to a variable, does anyone have an idea why, tell me if there is any needed information.

Thanks in advance.

EDIT:

Gamescreen Class:

package com.edac.unforgivingunderground;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;


public class GameScreen implements Screen{

UnforgivingUnderground game;
OrthographicCamera camera;
SpriteBatch batch;

public GameScreen(UnforgivingUnderground game){
    this.game = game;

    camera = new OrthographicCamera();
    camera.setToOrtho(false,1920,1080);

    batch = new SpriteBatch();

} 

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    camera.update();

}

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

}

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

}

@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() {
    // TODO Auto-generated method stub

}

Assets Class:

package com.edac.unforgivingunderground;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;

public class Assets {


public static Texture texture_back;
public static Sprite sprite_back;

public static void load(){

    texture_back = new Texture(Gdx.files.internal("logo"));
    texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    sprite_back = new Sprite(texture_back);
    sprite_back.flip(false, true);
}

}

Desktop Launcher:

package com.edac.unforgivingunderground.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.edac.unforgivingunderground.UnforgivingUnderground;

public class DesktopLauncher {
public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();

    new LwjglApplication(new UnforgivingUnderground(), config);
}

}

Main Class:

package com.edac.unforgivingunderground;

import com.badlogic.gdx.Game;

public class UnforgivingUnderground extends  Game{

public GameScreen game_screen;

@Override
public void create() {
    Assets.load();

    game_screen = new GameScreen(this);

    setScreen(game_screen);

}

Upvotes: 1

Views: 168

Answers (1)

MadEqua
MadEqua

Reputation: 1142

Not sure why it crashed (you should post the stack dump) but possibly it's because this line: Gdx.files.internal("logo"). Maybe you mean logo.png or logo.jpg. Also make sure that the image file does really exist on your assets folder.

Also, I belive your render method is missing one line.:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();

    Assets.sprite_back.draw(batch);
}

That way you'll render your sprite to the screen through the SpriteBatch. In your code you can see that you're not using it.

Upvotes: 0

Related Questions