Start using Scala

Go to core project and the desktop project, right click and select Configure, then add Scala nature

You should now have in the build path

“Scala Library Container”

Screenshot-Scala - Scala IDE

you need a Scala nature on both projects for adding Scala code to the core as well as running the program via desktop project. That said all logic should sit in core project if you are to run the final app on android and desktop.

find the SimpleGame.java class in the core project and delete it.

Create a new SimpleGame.scala class instead in the same package, with the following code

 

package bernardcjason.libgdx
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Colorclass SimpleGame extends ApplicationAdapter {
    lazy val batch = new SpriteBatch()
    lazy val font = new BitmapFont()
    override def create() {
        font.setColor(Color.BLUE);
    }
    override def render () {
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        font.draw(batch, "Hello world", Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
        batch.end();
    }
}

 

to enable scala when building from command line add

cat core/build.gradle
apply plugin: “scala”
dependencies{
compile “org.scala-lang:scala-library:2.11.6”
}

cat gradle.properties
org.gradle.daemon=true
org.gradle.jvmargs=-Xms128m -Xmx512m
org.gradle.configureondemand=true
org.gradle.jvmargs=-XX:MaxPermSize=512m

./gradlew clean desktop:run

./gradlew clean android:installDebug android:run

SeeĀ https://github.com/libgdx/libgdx/wiki/Gradle-on-the-Commandline#running-the-desktop-project