LibGDX
libGDX는 성능 의존 코드를 위해 일부 C와 C++ 컴포넌트를 포함, 자바로 작성된 자유-오픈 소스 게임 개발 애플리케이션 프레임워크이다. 동일 코드 베이스를 사용하여 데스크톱, 모바일 게임 개발을 가능케 한다. 윈도우, 리눅스, Mac OS X, 안드로이드, iOS, 블랙베리 OS, 또 WebGL 지원 웹 브라우저를 지원하는 크로스 플랫폼이다.
libGDX is a cross-platform Java game development framework based on OpenGL (ES), designed for Windows, Linux, macOS, Android, web browsers, and iOS. It provides a robust and well-established environment for rapid prototyping and iterative development. Unlike other frameworks, libGDX does not impose a specific design or coding style, allowing you the freedom to create games according to your preferences.
Categories
Ecosystem
프로젝트 셋업
몇 가지 참고사항:
- 현재 (2024-03-26) Gradle 이 아직 JDK 19를 지원하지 않는다. 따라서 libGDX 도 동일하다.JDK는 11~18 버전을 사용하자. 자세한 내용은 해당 페이지에서 확인.
- 또한 코틀린을 사용할 경우 HTML Export 가 지원되지 않는다. 참고하여라.
- 두 번째 스탭에서 gdx-setup.jar 파일을 다운받고
java -jar gdx-setup.jar
로 실행하면 프로젝트를 생성할 수 있다. - Android 프로젝트는 현재 (2024-03-26) SDK API Level 33 을 다운로드 받아야 한다. 참고하여라.
- Generate 하면 이것저것 다운받는다. 좀 오래 걸리니 참고하여라.
- Bullet: 3D Collision Detection and Rigid Body Dynamics Library.
- FreeType: Scalable font. Great to manipulate font size dynamically. However be aware that it does not work with HTML target if you cross compile for that target.
- Tools: Set of tools including: particle editor (2d/3d), bitmap font and image texture packers.
- Controller Library to handle controllers (e.g.: XBox 360 controller).
- Box2d: Box2D is a 2D physics library.
- Box2dlights: 2D lighting framework that uses box2d for raycasting and OpenGL ES 2.0 for rendering.
- Ashley: A tiny entity framework.
- Ai: An artificial intelligence framework.
출력로그는 다음과 같다:
Generating app in /home/user/Project/cw
Executing '/home/user/Project/cw/gradlew clean --no-daemon'
Downloading https://services.gradle.org/distributions/gradle-8.5-bin.zip
............10%.............20%............30%.............40%.............50%............60%.............70%.............80%............90%.............100%
Welcome to Gradle 8.5!
Here are the highlights of this release:
- Support for running on Java 21
- Faster first use with Kotlin DSL
- Improved error and warning messages
For more details see https://docs.gradle.org/8.5/release-notes.html
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.5/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build
> Task :android:clean UP-TO-DATE
> Task :core:clean UP-TO-DATE
> Task :desktop:clean UP-TO-DATE
> Task :html:clean
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 32m 28s
4 actionable tasks: 1 executed, 3 up-to-date
Done!
To import in Eclipse: File -> Import -> Gradle -> Existing Gradle Project
To import to Intellij IDEA: File -> Open -> build.gradle
To import to NetBeans: File -> Open Project...
Project Layout
This will create a directory called mygame with the following layout:
settings.gradle <- definition of sub-modules. By default core, desktop, android, html, ios
build.gradle <- main Gradle build file, defines dependencies and plugins
gradlew <- local Gradle wrapper
gradlew.bat <- script that will run Gradle on Windows
gradle <- script that will run Gradle on Unix systems
local.properties <- IntelliJ only file, defines Android SDK location
assets/ <- contains your graphics, audio, etc.
core/
build.gradle <- Gradle build file for core project
src/ <- Source folder for all your game's code
desktop/
build.gradle <- Gradle build file for desktop project
src/ <- Source folder for your desktop project, contains LWJGL launcher class
android/
build.gradle <- Gradle build file for android project
AndroidManifest.xml <- Android specific config
res/ <- contains icons for your app and other resources
src/ <- Source folder for your Android project, contains android launcher class
html/
build.gradle <- Gradle build file for the html project
src/ <- Source folder for your html project, contains launcher and html definition
webapp/ <- War template, on generation the contents are copied to war. Contains startup url index page and web.xml
ios/
build.gradle <- Gradle build file for the iOS project
src/ <- Source folder for your iOS project, contains launcher
Jython Setting
Basic
@Override
public void create() { }
@Override
public void resize(int width, int height) { }
@Override
public void dispose() { }
@Override
public void render() { }
@Override
public void pause() { }
@Override
public void resume() { }
-
create()
- 이름에서도 짐작 할 수 있듯이 게임이 만들어 질 때 기본적으로 불리는 함수다. 안드로이드의 onCreate()와 같다. 클래스의 변수를 초기화하는데 사용된다. -
resize(int width, int height)
- 게임의 크기가 변할 때 실행되는 함수며 이때 전달 인자인 width와 height는 변경되는 게임 스크린의 크기다. 게임 개발을 안해본 사람들은 크기가 변하면 무슨일을 해야할 지 감이 안올 것이다. Libgdx에서는 주로 이 함수에 viewpoint라는 변수를 재정의 해주는데 이건 다음 포스트에서 정리해야겠다. -
dispose()
- 메모리가 부족할 때 불리는 함수다. 게임 실행중에 특정 변수가 불필요하게 메모리를 많이 잡고 있다면 dispose 함수 내에서 처리해주도록 하자. -
render()
- Libgdx에서 가장 중요한 함수다. 이 함수는 1초에 60번 불리며 실제로 화면을 그려주는 일을 담당한다. 60fps를 적어도 보장하려는 모양이다. 개발자는 이 함수에 자신의 그림을 그린다. -
pause()
- 안드로이드의 onPause()처럼 게임이 중간에 멈추거나 종료될 때 불리는 함수다. -
resume()
- 이것 또한 안드로이드의 onResume()처럼 Pause 상태에서 다시 시작 될 때 불리는 함수다.
Projects used
- Simply Piano
- Slay the Spire by Mega Crit Games