Category Archives: libgdx

vr

see https://github.com/bernardjason/daydream

libgdx and daydream vr

sample of using libgdx to produce dual display for VR headset, in this case Daydream View. Not a library so you can see camera displacement when rendering to offset one eye along with two render operations to a framebuffer followed by use of shader to alter final frame.

This is essentially standard libgdx, using a shader to handle lens distort, otherwise straight lines would be warped. The android version uses the handheld controller to move the player around the small world along with spacial audio, via the Google VR SDK. The code for this is just in the bespoke Android module.

While desktop version uses arrow keys and spacebar to move along with some basic stereo audio using libgdx apis.

For the HTML version there is a very basic use of device orientation to move player view, but without allowing movement. It looks possible to integrate Daydream handheld controller with HTML version, see https://github.com/mrdoob/daydream-controller.js though I’ve not tired it. HTML version was really to check project is as close as possible to being able to work on ios. Though like HTML version I don’t see official support for handheld controller. Got around full screen problem when viewed on browser but sound does not work on mobile browser as not driven by user interaction.

android

to build and deploy

./gradlew android:installDebug

to make just the apk ./gradlew android:assembleDebug

daydream apk debug build apk

Tilt controller to change direction. Touch the touchpad to move while click touchpad when close and looking directly at spinning cube to drop it. Press App button (immediately below touchpad) will re-centre controller.

desktop deploy

./gradlew desktop:run

./gradlew desktop:dist

daydream desktop jar

HTML deploy

./gradlew html:superDev ./gradlew html:dist

Try online daydream for browser

hole in one, demo android/dekstop scala game using libgdx

I’ve produce this very simple game

source code available here https://github.com/bernardjason/holeinone

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
base

to a linear

terrain

For collision detection I’ve not used Bullet physics but rather sphere collision bernardcjason.gdx.basic.shape.CollideSphere.

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

Get going with libgdx

First get the setup application, libGDX uses Gradle rather than download the entire library

https://libgdx.badlogicgames.com/download.html

java -jar ~/Downloads/gdx-setup.jar

Screenshot-LibGDX Project Generator

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

Screenshot-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

Screenshot-Advanced Settings

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.

Screenshot-Import

 

Make sure you import core project and desktop project into eclipse.