Making a game in Java using LibGDX : Part 0 - Setting Up LibGDXsteemCreated with Sketch.

in #java8 years ago (edited)

libGDX-RedGlossyNoReflection.png

What is LibGDX?

LibGDX is a free open-source Java framework supporting multi-platform export (Windows, Linux, Mac, Android, IOS and HTML5). It supports custom shaders written in GLSL and extensions : Box2D (Physics) and Ashley (Entity Component System) being the most popular. It includes Scene2D which helps a lot with the UI.

Downloading LibGDX

Let's start by downloading the LibGDX setup .jar on the official download page here. Make sure you have installed the Java JDK and JRE on your machine.

Setting up the project

Double click the .jar or use java -jar gdx-setup.jar. You should be met with this screen.
Selection_138.png
Since we will make a Desktop only application I unchecked all the other exports, I also unchecked the Box2D extension because we will not use it. Do not worry, you can always add those back later if you change your mind mid-project. Fill in the other fields :

  • Name : The project name
  • Package : Your domain, if you don't have one just use org.yourname or org.yourname.projectname
  • Game Class : The name of the class that contains the first executed lines of code will be.
  • Destination : The path where the project will be set. I recommend creating an extra directory like this ../Desktop/GameDirectory/ if not you will get multiple files on your desktop.

My final setup looks like this :
Selection_144.png
Hit generate and it should successfully build!
Selection_145.png

Opening the project in your IDE

To open the project you simply need to follow the steps that the gdx-setup.jar app told us to do when building finished :

Selection_146.png

However you may require gradle or have other problems importing the project, the LibGDX wiki has a page to help you out here.

Configuring the desktop settings

Open the DesktopLauncher class to adjust desktop export related configuration. The DesktopLauncher class is found in desktop/src/yourpackage/desktop.

public class DesktopLauncher {
    public static void main (String[] arg) {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.width = 600;
        config.height = 600;
        config.backgroundFPS = 60;
        config.foregroundFPS = 60;
        new LwjglApplication(new SteemitTutorial(), config);
    }
}

I added a configuration for config.width and config.height, adjusting the screen size and also the targeted FPS with config.backgroundFPS and config.foregroundFPS.

Testing the hello world

Now run the project! I'm using IntelliJ as an IDE, I simply need to right-click DesktopLauncher class and press run. However I'm already met with this :

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: badlogic.jpg

If you encounter this problem, you simply need to go to Run>Edit Configurations (On IntelliJ) and add core/assets/ to our working directory. If you added the Android export, add android/assets/ instead.

Selection_147.png

If you see this screen, you successfully ran your first LibGDX game! Congratulations! Much more is to come!

Sort:  

Congratulations @loomy! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

nicepost shared :)

Hey thanks! Are you a human? If not beep bop hi bot

hi! I'm both :)

Coin Marketplace

STEEM 0.13
TRX 0.33
JST 0.034
BTC 111137.49
ETH 4320.98
USDT 1.00
SBD 0.83