I’ve pulled together some code I had to show how to put together something using libgdx and scala that can run on either desktop or android platform. I’ve not tried it with a Mac. This wont work with HTML flavour libgdx as it’s scala.
The game uses the arrow keys, mouse or screen press to move the gun. Press and hold the spacebar, mouse button or screen then release to fire a missile at the bouncing ball.
The intention of this code is something to pick the bones out of or use as a start for something else.
Things of note
file local.properties contains the location of the android sdk. So this needs to be changed to where you’ve installed it.
core/build.gradle has been changed to build scala source
class FlatTerrain extends class BaseTerrain. This class supports an uneven terrain as well as the simple flat terrain shown in the game.
class bernardcjason.gdx.basic.shape.Cuboid shows mapping parts of a texture to a cube. This is a change to the usual mapping of a texture shape which is
to a linear
For collision detection I’ve not used Bullet physics but rather sphere collision bernardcjason.gdx.basic.shape.CollideSphere.
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”
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
decide on package and game names. Also decide if you want ios and html version. I’ve never tried anything apart from hello world with html and I don;t have access to a mac to have tried ios. I always select desktop for testing my app and android as the end goal.
You may need to update android build tools if message
is displayed. If so run the tool within android sdk directory
tools/android update sdk
If like me you like using an IDE, select advanced settings to generate eclipse project files, so that you can import into eclipse later on
Once the code is generated by gdx-setup you can then go to eclipse and import the projects. The tool has created the .project, .classpath and .settings for you.
go to eclipse menu, select File then Import.
Make sure you import core project and desktop project into eclipse.