Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Tutorial: Write a libGDX game
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.
- Deploy and test
bin/libgdx.apkon 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"); end def render Gdx.gl.glClearColor(0, 0.25, 0.5, 1) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) @batch.begin @batch.draw(@img, 32, 64) @batch.end end end
- 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.)