Wiki
Clone wikiSpecGine / NewProject
Setting up a new project
Getting template
SpecGine currently provides only engine functionality that is cross-platform. You still need some code to manage which platform-specific code from Libgdx you will use. We highly recommend starting from great libgdx-sbt.g8 project template by Joseph Hager. You can also start coding your own template/project settings, but this is not recommended way to get your first project up and running quickly. In this tutorial we assume you have up and running SBT (Simple Build Tool, a build tool popular among Scala projects) and giter8. After you have those tools, you can proceed with getting libgdx-sbt.g8 template just like it was written on its homepage:
#!bash
g8 ajhager/libgdx-sbt-project
At first you will be asked for name of your project. We answer Ping
here. When asked for package, answer with package name for your new game. It should be unique, and usually start with reversed name of a domain you own. In this tutorial we will use com.specdevs.ping
. We leave default value for Android API level.
Make sure, that when asked about Scala and Libgdx version you pick one, that is designed to work with current version of SpecGine. For SpecGine 0.1.1, it is Libgdx 0.9.9 and Scala 2.10.4 It is also default version of libgdx-sbt.g8 project template at the time of writing this tutorial.
When everything finishes, you should see following text:
Template applied in ./ping
It means, that inside ping
directory you have a fresh template to develop using Libgdx and Scala for multiple platforms. We will now modify this template to use SpecGine.
Modifying template
We need to add engine to dependencies of core
sub-project. Locate
libraryDependencies ++= Seq( "com.badlogicgames.gdx" % "gdx" % libgdxVersion.value )
libraryDependencies ++= Seq( "com.badlogicgames.gdx" % "gdx" % libgdxVersion.value, "com.specdevs" %% "specgine" % "0.1.1", "com.specdevs" %% "specgine-macros" % "0.1.1" % "provided" )
%%
, not %
)
Because template is made to work with Scala 2.11, you need to adjust scalac options. Locate lines
"-Ywarn-unused", "-Ywarn-unused-import",
Modifying launcher code
Because template is designed to work with Libgdx 1.2, and SpecGine 0.1.1 is designed to work with Libgdx 0.9.9, we need to enable OpenGL ES 2.0 in desktop and Android code (default with newer Libgdx).
Locate file android/src/main/scala/Main.scala
and below line inside onCreate
method
val config = new AndroidApplicationConfiguration
config.useGL20 = true
desktop/src/main/scala/Main.scala
and below line
val cfg = new LwjglApplicationConfiguration
cfg.useGL20 = true
Modifying game code
Now it remains to modify game code to use SpecGine. Open file core/src/main/scala/Ping.scala
in your project template. It should look like:
#!scala package com.specdevs.ping import com.badlogic.gdx.Game class Ping extends Game { override def create() {} }
#!scala package com.specdevs.ping import com.specdevs.specgine.core.gdx.Game class Ping extends Game("com.specdevs.ping") { def initialize() {} }
Testing code
Now, we are ready to test our project settings. To do it, start SBT using
sbt
compile
command while in SBT.
compile
[success] Total time: X s, completed XXXX-XX-XX XX:XX:XX
It means everything went well, and you can start your application. We will use only desktop version for now, because it is easier for development. Still inside SBT, issue command:
desktop/run
[info] Loading project definition from .../project [info] Set current project to all-platforms (in build file:...) [info] Running com.specdevs.ping.Main [success] Total time: X s, completed XXXX-XX-XX XX:XX:XX
Having troubles with this step?
Here you can download project with all above steps completed.
Updated