Tutorial: Write a libGDX game

Ashiq A edited this page Aug 4, 2015 · 3 revisions

This is intended to replace the Gosu tutorial, since gosu-android is no longer maintained. You should have Ruboto already set up and have an idea of how to work with it. You also probably should have some experience working with libGDX.

This is pretty easy:

  • Clone the libGDX-Ruboto repository. This is a template repository which contains a dummy libGDX game, configured to run on Ruboto.
  • Run rake debug.
  • Deploy and test bin/libgdx.apk on your Android VM or device.

The core game code lives in src/main_game.rb. Feel free to restructure it to create your game however you want. Here's how it probably looks:

java_import com.badlogic.gdx.ApplicationAdapter
java_import com.badlogic.gdx.Gdx
java_import com.badlogic.gdx.graphics.GL20
java_import com.badlogic.gdx.graphics.Texture
java_import com.badlogic.gdx.graphics.g2d.SpriteBatch

# Your main game class. If you change the class name, make sure you update
# libgdx_activity.rb to specify the new game name.

class MainGame < ApplicationAdapter
	def create
		@batch = SpriteBatch.new
		@img = Texture.new("badlogic.jpg");

	def render
		Gdx.gl.glClearColor(0, 0.25, 0.5, 1)
		@batch.draw(@img, 32, 64)

This code:

  • Imports all the Java classes for libGDX
  • Creates a new spritebatch and loads the (default/starter) libGDX image
  • Draws it every tick on a colored background

Note that this uses JARs from libGDX 1.6.1 (the last release available in a zip file). If you want to upgrade, you need to scrounge Maven for the requisite JARs.

Also, if you're interested in a cross-platform game engine that uses Ruby, you may want to check out Terrace. (It uses JRuby and libGDX, with Ruboto to create the Android binaries.)

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.