
No title available
dirt enthusiast
Alisa U Zemlji Chuda
Monterey Bay Aquarium

shark vs the universe
TVSTRANGERTHINGS
No title available
RMH

Kiana Khansmith
2025 on Tumblr: Trends That Defined the Year
d e v o n
Peter Solarz
I'd rather be in outer space 🛸

pixel skylines
tumblr dot com
Cosmic Funnies
Today's Document

@theartofmadeline
One Nice Bug Per Day
AnasAbdin

seen from United States
seen from Brunei

seen from United States

seen from United Kingdom
seen from Netherlands

seen from United States
seen from United States
seen from United States

seen from Malaysia

seen from United States

seen from Vietnam
seen from United States

seen from T1

seen from Brazil

seen from France

seen from T1
seen from United States
seen from Germany

seen from Malaysia
seen from United States
@puzzlingplans
Featured
Feldspar Promo Codes!
If you like abstract turn-based board games, and want to see if you can beat our AI opponent, try Feldspar now with these App Store Promo Codes!
Feldspar will also be available on Android and on the web via WebGL, thanks to the libGDX and RoboVM frameworks.
How to redeem: http://support.apple.com/en-us/HT201209
696HXXXPE9FE EJ6N9W6JXANX WWFEH7R3YJFW JTWKWXPY7MWA FLPHYYYRWLNF MNL4FYYA9YTA EXKPYTWF64LA EPFKA69HPP7N WFXE7A76NPLL N7NYFTN46TWM A6LM9AFAL3AJ YJNHXAXALKRY
Building a Cross-Platform Game with libGDX, Part 4: Compiling to HTML5
libGDX can build a HTML5/JavaScript/WebGL version of your game that can be hosted on a web server. This is done using the Google Web Toolkit (GWT) which is mainly aimed at client/server apps, but also contains a nifty Java -> JavaScript compiler which performs the magic.
There are a couple of caveats, though. Firstly, the GWT runtime is not completely compatible with the standard, so many classes and method are missing (stuff like BitSet, AtomicInteger, Object.clone(), String.format(), etc). The omissions are pretty random, and although it's not hard to find substitutions, it's kind of annoying, especially when you want to use preexisting libraries.
Reflection is also omitted from GWT, but thankfully libGDX extends the compiler to add its own reflection mechanism. It's not perfect, but usually works well enough to dynamically load classes, create arrays, and convert objects to/from JSON.
It can be a bit opaque to figure out how all of this hangs together during development, though. There's an Eclipse plugin for GWT, but I found myself using Gradle at the command-line. Still, I had problems figuring out where my files went and how to properly run them in a browser. There are two different modes, SuperDev for development and Production mode -- the former is slow and debuggable, the latter is obfuscated and fast.
Once you get it working, it's not that bad. Fortunately I had only a handful of JavaScript exceptions that had me tearing my hair out for a few hours. I even wrote a replacement for Object.clone() in JavaScript that seems to work well enough for my purposes. You can easily inject JS into Java source files with GWT.
But there are fundamental differences between the web and a mobile app. Threads don't exist. Files don't really exist, but I hacked up a solution that uses cookies to store small bits of game state and preferences. You could also use the LocalStorage feature of the browser; GWT makes it pretty easy to manipulate the parent page's DOM and invoke methods.
There isn't even a System.out by default, just libGDX's own logging facility, but I hacked that up too -- I can't live without my println()!
So what have you got at the end of all of this? Surprisingly, a game that looks pretty much like the mobile version. WebGL handled everything I threw at it, including the shaders. The code translated fine, but it runs pretty slow -- slower than my mobile devices. The good news is that profilers work fine, at least in Super Dev mode. And funny enough, GWT does emulate Java stack traces -- though I haven't tried deobfuscating them in Production mode.
It's going to be interesting to compare this with Unity's asm.js solution. One plus of the libGDX/GWT combo is that the entire stack is debuggable (in dev mode) from top to bottom. I don't see that being quite as simple with C/C++ cross-compiled code. You also get the JS engine's garbage collector for free.
Not all of the native support is available, like font rendering (libGDX uses a native Java version of Box2D for GWT). Still, everything is JavaScript, so you could in theory compile your physics engine or whatever with Emscripten and hook it in yourself. You'd just have to write some glue code to marshal everything over to the heap.
I'm hoping browsers continue to improve and we'll get faster games without having to retool -- and please, JavaScript spec-keepers, hurry up with 64-bit integers already!
Automatically Generating All Those Icons With a Makefile
The latest versions of Android and iOS require apps to include 14 different sized icons and 5 different sized default images. I wrote a little Makefile to do this for me on demand using ImageMagick and pngquant (you could use pngcrush with a little rewriting).
The default images have different aspect ratios, but the script crops out the edges on the longer ones.
You're also going to have to make sure your Info.plist contains references to all of the icons; you can do this directly or via XCode.
Building a Cross-Platform Game with libGDX, Part 3: iOS and RoboVM
Recently Google revealed their new Inbox app, the iOS port of which uses their j2objc tool to translate Java source to Objective-C. I thought I would share a few experiences with RoboVM, which compiles JVM bytecode directly into native iOS binaries.
When developing a game, the libGDX and RoboVM libraries contain almost all of the cross-platform support you'd want. The only platform-specific code you absolutely need is a small launcher, which looks something like this:
public class IOSLauncher extends IOSApplication.Delegate { @Override protected IOSApplication createApplication() { IOSApplicationConfiguration config = new IOSApplicationConfiguration(); config.preventScreenDimming = false; config.orientationPortrait = true; config.orientationLandscape = false; config.depthFormat = GLKViewDrawableDepthFormat.None; config.useAccelerometer = false; config.useCompass = false; config.allowIpod = true; return new IOSApplication(new AppMain(), config); } public static void main(String[] argv) { NSAutoreleasePool pool = new NSAutoreleasePool(); UIApplication.main(argv, null, IOSLauncher.class); pool.close(); } }
Note that IOSLauncher implements UIApplicationDelegate, so you can add delegate methods for app lifecycle, push notifications, URL handling, etc. right in this file. You also have access to the main UIViewController.
If you need to implement functionality not provided by the base libraries, RoboVM has a bridge to C or Objective-C native code. It's fairly simple to use, for instance I need to extend the default bindings to add an iOS 8-specific API call:
@Library("UIKit") @NativeClass class UIPopoverPresentationController extends NSObject { @Property public native void setSourceView(UIView v); }
Unlike JNI there is no native glue to write! Fortunately RoboVM has a pretty complete set of Cocoa Touch bindings, so usually the binding you need already exists, for example:
UIActivityViewController controller = new UIActivityViewController(activityItems, null); iosApplication.getUIViewController().presentViewController(controller, true, null);
In most instances you'll want to design an interface that exposes the desired functionality, then implement it against the different platforms, using Class.forName() to look up the platform-specific implementation. I've implemented bare-bones advertising, game services, IAP, and sharing interfaces along these lines.
There are still a few outstanding areas, for example stack traces are not exposed to the app, so you can't walk stack frames and printStackTrace() does nothing. However, you can install the Flurry bindings (or pick your favorite crash reporting tool) and enable crash reporting:
private void setupCrashReporting () { Flurry.setCrashReportingEnabled(true); Flurry.setAppVersion(APP_VERSION); Flurry.startSession(API_KEY); }
Unfortunately this isn't the entire picture, because in my tests the symbolication for my app's code was wrong (Flurry uses their own symbolication engine AFAIK) and I had to do it manually using the command line. Hopefully this will get better.
There's also no console output by default on iOS targets, but you can easily whip up a class to pipe it to Foundation.log(), e.g.:
System.setOut(new FoundationLogPrintStream());
How's performance? Pretty good, although I haven't measured in awhile. For my app, which has some CPU-intensive calculations, it seems a Kindle Fire HD and iPad 3rd gen are on about equal footing (ignoring GPU differences of course). You can take full advantage of multithreading and the RoboVM folks have done some optimizations to optimize memory allocation for this case.
There are GC pauses, but I haven't really noticed them often, and I don't go out of my way to avoid creating garbage either. You can also use the XCode Instruments tools to profile your app (among other things) and the stack traces are pretty well understandable.
Building a Cross-Platform Game with libGDX, Part 2: Setup
libGDX has a setup UI that creates the initial project directory structure, and installs any plugins you may need (like font rendering, physics library, etc). This is only done once, and from there you are left to tweak to your heart's content.
Here's what my main project directory looks like:
Seems pretty complicated, but there's a lot of stuff here. There are separate directories for code specific to the Android, iOS, Desktop, and HTML targets, and code shared by all projects (I added 'shared' later to denote code that is not game-specific but shared by all projects). The platform-specific code is typically very small.
I put most of my source art in the "art" directory, but by convention the final assets live in "android/assets" and the other targets copy or refer to them as needed.
Gradle is the command-line build tool used by libGDX. It's pitched as a lightweight alternative to the enterprise-y Maven tool and a more powerful alternative to the tried-and-true Ant tool. But it also uses Maven to find dependencies. And your build scripts are actually written in a programming language called Groovy. And ... never mind. Explaining it all could fill up an entire blog.
You can use Gradle as an Eclipse plugin but it's useful to know how to use the command line. To build stuff you do something like this:
./gradlew android:assembleRelease ios:createIPA html:dist desktop:dist
This builds an APK for Android, an IPA for iOS, and a bundle for HTML5. Here's what building the desktop version looks like (on a good day):
Now I have a "desktop-1.0.0.jar" file I can run immediately, or use something like JarWrapper to package it into a nice installable package.
The Android target is pretty straightforward, as it relies on Google's Android build tools and Gradle plugin.
The iOS target uses a tool called RoboVM, which is a Java compiler and runtime library that uses Apple's XCode tools on the backend. Sometimes this takes awhile when RoboVM has to recompile all of your class files into native code, but you can build and launch your app on the device or simulator right from the command line.
The HTML target uses the Google Web Toolkit (GWT) which among other things contains a Java-to-JavaScript compiler. The Java dialect spoken is not strictly compatible with the JDK (not even as compatible as Android) and lots of library classes are not available. With a little elbow grease, you can work around the limitations, but it'll be a bit ugly. I have separate versions of some of my source files that are specific to the GWT and automatically copy them in before the build.
RoboVM works very well, and I haven't had any real issues that weren't related to binding to native iOS frameworks (and these were resolved). Debugging is a bit of a problem as Java stack traces are not available when exceptions are thrown, but there are other ways, like piping stack traces to Flurry (more on that later).
GWT is fine once you get it set up properly, but the performance lags both the Android and iOS ports. For my AI routines I use a lot of 64-bit integers which are emulated in JavaScript, so this probably contributes. Debugging is also tricky. Threads don't exist. Nevertheless most of the code and shaders translate perfectly to WebGL, and it's pretty amazing.
Next time I'll go into specifics of each platform, and how you bind to things like ad networks and social media APIs.
Building a Cross-Platform Game With libGDX, Part 1
I've spent last four years working on a suite of apps written in the native tongue of their platforms -- Objective-C (iOS), Java (Android) and C# (Windows Phone).
A lot of thought went into their design and they've been very successful. However, they had been accumulating an awful lot of technical debt which would be very difficult to pay back entirely -- some of the code dates back to iOS 2.x and Android 1.5! At the rate new SDKs are released and features deprecated, it seemed we spent way more time upgrading, fixing and testing than developing new features, and that seemed wrong.
For my next project, I was determined to use a toolchain that I might be able to sustain for the long haul. It had to be cross-platform, relatively stable, extensible, and have a snowball's chance of compiling clean in five years.
Straight C/C++ was an obvious choice, but I've written a lot of each and just spend too much time fiddling or trying to clean up my previous messes. And I wasn't looking forward to debugging Emscripten-generated output should we decide to compile against the web (ok I kinda was, but that's not healthy).
Unity of course is another obvious choice. I just can't get used to the visual workflow and endless property editors; I think much better in text. I know there are frameworks that allow you to bypass most of the visual stuff and code directly against the APIs, but then the point of using the framework seems blunted. I was worried about having to continually debug a closed-source product. I also didn't like MonoDevelop very much, although I've had good experiences with Visual Studio in the past -- this time, though, I wanted to be able to develop on multiple platforms.
Then I came across the libGDX project. It has been around since 2010 as an Android-centric game library, and has recently been given backends for iOS and WebGL. It's compatible with the Eclipse IDE, which I've had lots of experience with. Java isn't the sexiest language (or the most open, but we'll save that topic for later) but it has remained fairly stable and backwards-compatible throughout its history. As a bonus, the framework runs perfectly well on Ubuntu -- much faster, I think, than on OS X. New builds run in mere seconds.
In the next post I'll talk about the pros and cons of building a game with libGDX and how it generates iOS and HTML5 apps.
When you use a git visualizer, making games looks easy!
Here's our new turn-based board game, Feldspar -- coming soon on iOS/Android/WebGL!