Showing posts with label libgdx. Show all posts
Showing posts with label libgdx. Show all posts

Sunday, February 22, 2015

libgdx and Universal Tween Engine

Today I have decided that I will be using the Universal Tween Engine for my Pitch game project's tweening needs.

What is the Universal Tween Engine?
The Universal Tween Engine enables the interpolation of every attribute from any object in any Java project (being Swing, SWT, OpenGL or even Console-based). Implement the TweenAccessor interface, register it to the engine, and animate anything you want!
It's actually pretty damn cool, and easy to use. At first I didn't think it would suit the simplicity of my project, and would make it bloated and be confusing to work with. I was dead wrong.

Using the Universal Tween Engine is quite simple. I have put together a very short demonstration of using the Universal Tween Engine to tween the position and opacity (alpha) of a libgdx Sprite. I used gdx-setup.jar to generate my project and I copied the sources of the Universal Tween Engine from it's directory which I cloned using mercurial into my project's code/src folder. See below.


The only source file which you really need to worry about is the MyGdxGame.java file which I have put up on github as a gist for reference.


I am not going to go into detail explaining things here, but the docs for the Universal Tween Engine are more than adequate to tell you what is what.



Experiment (Pitch) States

Here is a simple diagram showing the different 'states' that the Pitch game can be in at any one time. The notation I am using here has primary and secondary states shown. Second states have the primary state and two colons then the secondary state name.

Pitch Game States
The game should start in the Splash state, then progress to the Title state, then to the Play state, which then has 3 secondary states which the game will transition through, before returning back to the Title state.

The game will eventually become more complex once we add Credits, and Social Integration states, but this will suffice for now.

Thursday, February 19, 2015

Testing libgdx projects on the desktop while using Android Studio

If you have tried to use libgdx with Android Studio and found that you are unable to run the Desktop build, I would like to inform you that it now indeed possible, just takes a few more steps than running the android build.

First in Android-Studio click on the Gradle tasks bar at the right side of the screen. Then click the little arrow on the left of your gradle project name under the All tasks category, scroll all the way down to the :desktop section and click on the right arrow on the left of :desktop, and again scroll down and find the run task and double-click on the run task.

This will attempt to run your desktop project. Provided you have no errors, you should see your libgdx game window appear just like it used to with the older style Eclipse based projects.

Now, once you have done this, you can click on the Run menu item in the main window menu bar and choose Edit Configurations.

You should now have a new Run/Debug Configuration under the Gradle section called yourprojectname:desktop [run]. You may use this new configuration to run your desktop project without needing to find the run task in the long list of tasks.

I hope that this little mini tutorial has helped you work more efficiently with libgdx and Android Studio. It certainly was a wonderful thing to find today for me, as I have been cursing out Android Studio for it's lack of desktop application support ever since I downloaded it.

I used to curse about libgdx adopting Gradle for it's projects, but now, I certainly agree that it was a good move, and that it makes things a lot simpler. It all needs better documentation though. Things like this should be available right in the setup docs, without having to dig into the software blindly and happen across the answer.