Wiki

Clone wiki

SpecGine / 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
    )
and change it to
    libraryDependencies ++= Seq(
      "com.badlogicgames.gdx" % "gdx" % libgdxVersion.value,
      "com.specdevs" %% "specgine" % "0.1.1",
      "com.specdevs" %% "specgine-macros" % "0.1.1" % "provided"
    )
(note, that we are using %%, not %)

Because template is made to work with Scala 2.11, you need to adjust scalac options. Locate lines

      "-Ywarn-unused",
      "-Ywarn-unused-import",
and remove them.

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
add line
    config.useGL20 = true
Then locate file desktop/src/main/scala/Main.scala and below line
    val cfg = new LwjglApplicationConfiguration
add line
    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() {}
}
Change it to use Game class from SpecGine.
#!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
in project root directory, and wait for it to download some files. Then issue compile command while in SBT.

compile
Again, SBT will resolve dependencies and now compile your project. It should finish without warnings with message like:
[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
You should see something like
[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
and a black window showing up, and disappearing soon. It means everything works, just we have not added any State yet. We will do so in next part of this tutorial, when we will add main menu to our screen, so we can keep the window open for a while.

Having troubles with this step?

Here you can download project with all above steps completed.

Updated