Created
November 6, 2019 22:52
-
-
Save mgsx-dev/c0e7244dc7b542e079f888af8d180456 to your computer and use it in GitHub Desktop.
Custom splash screen with Libgdx and Lwjgl3 backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.Input; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.Texture; | |
import com.badlogic.gdx.graphics.g2d.Batch; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
public class DesktopLauncherWithSplash { | |
public static void main (String[] arg) { | |
showSplashScreen(); | |
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); | |
new Lwjgl3Application(new ApplicationAdapter(){ | |
// your game here | |
}, config); | |
} | |
private static void showSplashScreen() { | |
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); | |
config.disableAudio(true); | |
config.setDecorated(false); | |
config.setResizable(false); | |
config.setTransparentFramebuffer(true); | |
new Lwjgl3Application(new ApplicationAdapter() { | |
private Batch batch; | |
private Texture texture; | |
private float time; | |
@Override | |
public void create() { | |
// load your PNG | |
texture = new Texture(Gdx.files.classpath("splash.png")); | |
batch = new SpriteBatch(); | |
} | |
@Override | |
public void render() { | |
time += Gdx.graphics.getDeltaTime(); | |
// render your PNG | |
Gdx.gl.glClearColor(0, 0, 0, 0); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1); | |
batch.begin(); | |
batch.draw(texture, 0, 0, 1, 1); | |
batch.end(); | |
if(Gdx.input.isKeyJustPressed(Input.Keys.ANY_KEY) || time > 2f){ | |
Gdx.app.exit(); | |
} | |
} | |
@Override | |
public void dispose() { | |
texture.dispose(); | |
batch.dispose(); | |
} | |
}, config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment