Is Ruby Good for Game Development?

    Geza Gog

    For a long while it seemed that the Flash hegemony is unbeatable in the market of online games. Then Apple announced that their (then) new mobile device – the iPhone – won’t support Flash because of performance issues. This forced game developers to find new alternatives rapidly.

    For application developers,there is an ongoing argument when it comes to which is the best language to use for game development. On one hand, they need a simple environment that lets them use their imagination and creativity for executing their ideas instead of having to focus on function libraries and code classes. On the other hand, the final application must run fast and smooth to provide the best user experience and must work on all the major platforms.

    Ruby achieves a great balance between performance and simplicity with easy coding features. Let us examine some of its main features and see if it can be used to build web based games.

    A comprehensive library pack called RubyMotion with great features and tools has been published to extend Ruby for iOS, so you can now easily use the dynamic Ruby language for developing iPhone or iPad games.

    There is a downside though. When it comes to performance there are definitely better languages. In order to get the same performance level as you would in C++, for example, you need to be very creative and put in a lot of time when it comes to Ruby. But thanks to its dynamic nature and the option to compile to Ruby code to flash or iOS apps, Ruby gives developers a lot of flexibility which allows a creative and experienced developer to manage just fine with its language limitations.

    Another important question to examine is whether the necessary technology exists to build games. Is there enough support for components such as graphics, audio playback and user interaction? Ruby has all that and more. Since it is an open source language, it keeps evolving and changing.  Just about any obstacle is handled by thousands of programmers that turn it into a challenge and often share their findings with the Entire Ruby community. There are also packages to give OpenGL support in a fast and accelerated way. You can find solutions for 3D games with G3Druby or the powerful Gosu library for 2D games development.

    The ultimate gem in all this is the Rubygame, which offers an independent multimedia library platform that provides all game features in a simple and effective way for Ruby programmers (In case you want to run Rubygame on Windows, I suggest you to download and set-up dependencies from the Man With Code Rubygame Setup tutorial, where you can find some simple videos about the whole set-up process as well).

    When our great new game is ready, the next question is how we can reach millions of users with it and how we can present our vision on their computer. Luckily we have out-of-the-box solutions to do it. For example, iOS is supported via the previously mentioned RubyMotion.

    But you don’t need to worry if you prefer good old Flash.

    There’s an open source compiler, called ‘Ruby On Flash’ that compiles your Ruby code into an .swf file., This gives you the option to move the game development process to the programmer friendly environment.

    Being a developer working in the gaming industry, let me demonstrate the ease of Ruby (using Gosu) with a simple “scratch-off” script, that operates similarly to the well-known cardboard scratch-cards, where an image or symbol is hidden under the coating. In the online version the mouse is taking the part of the coin, scratching over the coating and uncovering the icons.  Here, I  simply

    Here’s how it looks:
    [gist id=”4245320″]

    You can see that Ruby’s syntax allows for clear intention of code while performing some relatively complex graphical functions.

    If you have any experience developing games with Ruby, please tell us about it in the comments.  Thanks for reading!

    CSS Master, 3rd Edition