-
Notifications
You must be signed in to change notification settings - Fork 0
Using libgdx with Scala
Scala is a functional, object-oriented programming language for the JVM that works seamlessly with Java libraries, frameworks, and tools. It has a concise syntax and a REPL, which makes it feel like a scripting language, but it is being used in mission critical server software at companies like Twitter and LinkedIn.
Due to how GWT works you will not be able to use the HTML5 target with Scala
The default build created by the gdx-setup.jar tool is the best place to start when going the Gradle route. A repo with the required modifications to the default "blank" gdx project can be found here: gdx-scala-demo. These changes have been outlined below.
In order to support Scala compilation you need to update the build with a couple of additions:
- /gradle.properties
- Increase the heap used by gradle (otherwise you might have trouble compiling for iOS).
- /build.gradle
- Add the Scala plugin to the
project(":core")
section:apply plugin: "scala"
- In the dependencies include the scala library:
compile "org.scala-lang:scala-library:2.11.7"
- Add the Scala plugin to the
- /core/build.gradle
- Apply the scala plugin at the top of this file.
-
optional Set the src directory for scala files:
sourceSets.main.scala.srcDirs = [ "src/" ]
- /android/build.gradle
- In the
android
section (top of the file) you need to add the following:lintOptions { abortOnError false // make sure you're paying attention to the linter output! } // FIXME: How can we apply this simply for all builds? Copy-pasta makes me sad. buildTypes { release { minifyEnabled true proguardFile getDefaultProguardFile('proguard-android-optimize.txt') proguardFile 'proguard-project.txt' } debug { minifyEnabled true proguardFile getDefaultProguardFile('proguard-android-optimize.txt') proguardFile 'proguard-project.txt' } }
- In the
- /android/proguard-project.txt
-
In order for Proguard to work you need to add the following lines:
-dontwarn sun.misc.* -dontwarn java.lang.management.** -dontwarn java.beans.**
-
It might also be required to then change the line
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
to-dontwarn com.badlogic.gdx.jnigen.*
-
With all of these changes in-place you should be able to use Gradle exactly as you would otherwise from the shell or your favorite IDE.
The standard tooling for working with Scala is quite different than what Java developers will be used to. There is a project, libgdx-sbt-project, that provides a simple path for getting started with libgdx and Scala using standard build tools and best practices.
This tutorial assumes you have installed g8 and sbt 0.12, which are used in the Scala community for generating and interacting with projects.
In your favourite shell type:
$ g8 ajhager/libgdx-sbt-project.g8
After filling in some information about your project, you can start placing your game's source files and assets in common/src/main/scala and common/src/main/resources, respectively.
Update to the latest libraries:
$ sbt
> update
Run the desktop project:
> desktop/run
Package the desktop project into single jar:
> assembly
Run the android project on a device:
> android/start
Visit android-plugin for a more in-depth guide to android configuration and usage.
Run the ios project on a device:
> ios/device
Visit sbt-robovm for a more in-depth guide to ios configuration and usage.
Run all unit tests from desktop, android and common (subdirectories src/test/scala):
> test
Run specific set of unit tests:
> common/test
In most cases you will be able to open and edit each sub-project (like common, android or desktop), but you still need to use SBT to build the project.
See here for details about sbt plugins for each editor.
- Wiki Style Guide
-
Developer's Guide
- Introduction
- Setting up your Development Environment (Eclipse, Android Studio, Intellij IDEA, NetBeans)
- Creating, Running, Debugging and Packaging Your Project
- Working From Source
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Querying & configuring graphics (monitors, display modes, vsync)
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Taking a Screenshot
- Profiling
- Viewports
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprites * 2D Animation * Clipping, With the Use of ScissorStack * Orthographic Camera * Mapping Touch Coordinates ?? * NinePatches * Bitmap Fonts * Distance Field Fonts * Color Markup Language * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * Texture Compression * 2D ParticleEffects * Tile Maps * scene2d * scene2d.ui * Table * Skin
- 3D Graphics * Quick Start * Models * Material and Environment * ModelBatch * ModelCache * ModelBuilder, MeshBuilder and MeshPartBuilder * 3D Animations and Skinning * Importing Blender Models in libGDX * 3D Particle Effects * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Internationalization and Localization
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path Interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Tools
- Extensions
- Artificial Intelligence
- gdx-freetype
- gdx-pay: cross-platform In-App-Purchasing API
-
Physics
* Box2D
* Bullet Physics * Setup * Using the Wrapper * Using Models * Contact Callbacks * Custom Classes * Debugging
- Using libGDX With Other JVM Languages
- Third Party Extensions
- Third Party Services
- Articles