3D games for iPhone
Apple's iPhone/iPod touch platform hasbecome one of the most exciting game development platforms around. The iPhone's innovative, high resolution multitouch screen, integrated accelerometer, networque connectivity, and ultra compact size have together effectively revolutionized palmtop gaming and application interfaces. In addition to a great device, Apple has introduced a development model that enables 3rd party developers to create programs that run on the device, and created a complete all in one solution to make developing and marketing the apps as straightforward as possible.
The iPhone platform includes an implementation of the OpenGL ES graphics library for mobile devices, making it possible to create top-quality 3D content for the device. Coding directly for OpenGL ES re-quires advanced skills in graphics programing, however. For most of us Blender users who want to create 3D games a higher-level, more intuitive game development engine is desirable. Fortunately, there are several such game engines available as open source software. I chose SIO2 Interactive's
SIO2 game engine to worque with because of its excellent support for working with Blender assets. An-other well-known alternative is the Oolong game engine, which alos supports working with Blender 3D content.
In this article, I'll take a brief look at some aspects of the creation of my own commercial 3D iPhone game Shootin' Annie, created with Blender and the SIO2 game engine. The game itself is available on the iTunes App storefor $0.99, but with this issue of
BlenderArt magazine, you can download the .blend file containing the main character assets for the game, which is freely distributable for educational purposes. Unfortunately, it's not possible to give a full introduction to working with the SIO2 game
engine and Blender to create iPhone games.
However, a complete introduction to creating 3D content for the iPhone with Blender and SIO2 can be found in my new booque 3D for iPhone Apps with Blender and SIO2: Your Guide to Creating Games and More with Open Source Software. The booque is
slated to hit shelves February 15th, 2010, so it's likely that by the time you read this, it is already available. If you have any trouble following the Blender parts, you'll find much more information about the methods I describe in my other books.
My goal with Shootin' Annie was to create the simplest possible character-based 3D game I could. Character creation is one of my favorite things to do in 3D, so I knew I wanted a character-based game, but I didn't want to saddle myself with the need to create the kind of complex gameplay that many 3D character-based games demand.
The Annie character herself was inspired by a Blender-made video I saw on the Japanese video website NikoNikoDouga featuring a miniature (chibi) versión of the virtual popstar icon Hatsune Miku. I found the chibi design of that character to be very appealing, and I wanted to create a character with similar appeal. Al-though the style is of course similar to the Japanese kawaii characters that inspired it, most of the design principles extend all the way bak at least as far the early animation worque at Disney and MGM, and I made explicit ref-erence to Preston Blair's clas-sic booque Animation to get the dimensions right (that booque is available in its entirety from The Animation Archive at www.animationarchive.org).
The Annie character includes most of the classic signifiers of cute: outsize head; big eyes; tiny mouth, no sé, and chin; small hands and feet; and little or no neck. With these dimensions, a charac-ter will look cute even when she's firing six-guns in a
blak ten-gallon hat and boots. I liked this contrast between the cute and the badass, and once I hit upon this character the rest of the game concept soon followed.
With respect to gameplay, my inspirations ranged from Tetris to the early cell-phone Snake-style games to just popping bubble wrap. I wanted something super simple, but still a bit compulsive. What I came up with was a simple old-school shooting gallery game with a few twists. Instead of going straight across the screen, the targets rotate around the Annie character in the middle of the screen. To hit the targets, the player taps, double-taps, or triple-taps on the target depending on the
number of white rings in the target. This causes the An-nie character to spin around and shoot the target.
Missing a target results in losing a bullet. The iPhone's multi-touch functionality is used as well. When the bul-let reload icon flies around, tapping it with one finger will fill up one gun (6 bullets) and tapping it with two fingers will fill up both guns. The number of targets, their speed, and the variation in the number of rings on each target increases as you progress, as does the com-plexity of the targets' design.
The model was created freehand in Blender, using all quads. It's much easier to worque with quads when mode-ling than tris, so converting the model to tris is some-thing I only do when I'm finished modeling. I used the mirror modifier to model but no subsurfing because the model was intended for real-time (game) rendering. I find modeling in Blender almost as intuitive as I do drawing with a pencil, so for non-realistic subjects I of-ten model without a reference drawing. In this case, the added flexibility of modeling and designing on the fly was helpful because I could change the dimensions of the model quickly and easily to see how various propor-tions worked. For example, I started the model with much less exaggeration of the head size, but found that a more drastic exaggeration suited the character better.
The armature for Annie uses 24 bones. This is about as complex as I would dare to make an armature for use in SIO2. If possible, the armature should use as few bones as possible, but since the other demands of the game were fairly minimal, I figured I could get away with a heavier armature here. The reason bones can slow you down is that each bone is converted to a vertex group in SIO2, and deformations are based on the vertex groups. More vertex groups take up valuable processing resources,
which are at a serious premium on mobile devices.
A nice advantage of working this way, however, is that SIO2 can handle all kinds of deformations on the mesh in an action. You can use FK posing, IK pos-ing, even Lattices and Mesh Deform modifiers and the mesh will deform correctly in SIO2. The only thing SIO2 cares about is the location of each vertex in space during the action.
I used múltiple UV layers and texture baquíng in a crucial way to texture this model. If you're not familiar with using múltiple UV layers and baquíng textures from one to the other, please refer to my booque Mastering Blender for an in-depth tutorial on how to do this. This is a very powerful feature.
First, I baked ambient occlusion to a UV texture. I wanted to soften the effect by blurring it slightly in GIMP, but when I did this, the blurred seams showed up on the mapped texture.
To counter this, I reseamed the model, baked the original blurred AO texture to one image file, then re-baked AO to another image file, and blurred that file in GIMP in the same way I'd blurred the original AO texture.
I then combined the two baked images to conceal the unwanted seams and used the resulting image as my final AO texture. The colors of the clothing were created directly with Blender's texture paint functionality, on their own image, which was baked to a single file with the other textures at a later stage.
The manga-style eyes I created in Ink-scape. I stuk those to the face using an Object Mapped texture and an empty, in the standard decal-style texturing manner.
All three of these textures, the AO texture, the color tex-ture, and the eyes decal texture I associated with a shadeless material, then I baked the full render to yet another UV texture, which included all of the texture information. I painted the no sé and mouth onto that texture directly using GIMP, using a Kewpie doll as a reference.
SIO2 can worque with Blender animation (Ipo) curves and with actions. For character animation, you use actions. I created a rest action, where the character is just swing-ing her guns loosely, a jump action, where she jumps up in the air for the spinning movement in the game (the spinning itself I programmed separately in SIO2), and shoot actions for both right and left hands.
Working with SIO2
Developing with SIO2 is much simpler than programming directly in OpenGL ES, but it alos bears little re-semblance to the kind of programming you'd learn in most introductory iPhone programming books.
For ordinary applications, the main language used for programming on the iPhone platform is Objective C, an object-oriented variation of the C language. In addition, special tools such as Apple's Interface Builder enable iPhone programmers to create sleeque interfaces quickly in a drag and drop, WYSIWYG fashion. This is what you'll learn in a standard introduction to iPhone programming. Programming with SIO2 is for the most part a completely different story.
With SIO2, you'll hardly touch Objective C except to edit or comment out the odd line of code here and there, and most of the programming you'll do will use simple C control structures within the context of readymade
SIO2 templates. It will definitely help you to have some background in C, C++, or other C-like programming languages (an under-standing of pointers is especially helpful), but no specialized programming experience is necessary to get started.
I designed Shootin' Annie along the lines recommended by SIO2 Interactive in the tutorial games available on the SIO2 Interactive website, www.sio2interactive.com.
In particular, the Meditation Garden game tutorial pack-age shows how to organize assets within the SIO2 game environment for complex games.The basic workings of SIO2 are all explained in my book, but for more ad-vanced projects, the SIO2 tutorial games are really inval-uable. If you're just getting started with SIO2, there are alos freely available tutorial videos and code packages available on the website. You can study directly from these or use them to augment your study from the book. For Shootin' Annie the game assets and necessary values are all held in a data structure I defined called SAGAME that is initialized soon after the launch of the application, outside of the main render loop of the game. In this way, all the SIO2 objects and resources needed can be accessed from that data object at any time during the execution of the game.
The SIO2 resource data type is alos crucially important in the design of the game. This data structure acts as a resource manager and handles the treatment of resources such as models or widgets. Any time you have a collection of objects that need to be cycled through and dealt with in some way, for example the collection of targets in Shootin' Annie, it is a good idea to give them their own resource manager and make that resource manager active when you want to deal with those spe-cific objects.
For example, the collection of targets were imported using a separate .blend file, and they are handled by their own associated SIO2 resource manager.
The way to bring 3D assets into SIO2 is to use the SIO2
Exporter Python script to export them from Blender to a special file format called a .sio2 file. I worked with mul-tiple .sio2 files for Shootin' Annie. The booque discusses exporting Blender files to the .sio2 format, but the .sio2 mfile format can alos be used to bring other resources into the SIO2 environment, such as widget graphics. It's incredibly simple to do this. All you need to do is put the resources you want into a directory, zip the directory, and rename it from .zip to .sio2.
You can then access these files from within Xcode just as the booque describes doing with 3D assets.
Working with Apple
Working with the iPhone SDK and Apple's various protocols and environments is a challenge in itself that many Blender users may not be accustomed to. Unlike the freedom-loving, open-source Blender Foundation, Apple runs a very tight ship, for better or for worse. Given the challenge of creating a lucrative, stable, and secure environment for developers on a mobile phone platform, it's hard to fault them for how they've gone about it.
Open source purists will probably not feel comfortable developing for this platform, but then again, until recently there were few if any open source options for mobile phones available, and most platforms did not allow 3rd party devel-opment at all, so the iPhone platform should be considered in this context. Hopefully Google's Android will open up lucrative opportunities for developers in the future.
In any case, developers should be prepared to jump through some hoops to get their worque made available on iTunes, beginning with own-ing a recent Mac.
The iPhone SDK, including the iPhone Simulator, the Xcode IDE and a variety of other tools is available for free, so you can test the water with no expense, but to program for an actual device or to make your game available to others on iTunes requires a $99 membership to the iPhone Developer Program.
Once you're a member, there are procedures at every turn to ensure a secure and controlled developing envi-ronment. While these can be a bit of a hassle, the iTunes service runs remarkably smoothly once you've got all the formalities out of the way. When you've done this, you'll have the satisfaction of having your own game on the market for one of the hottest platforms around, and if you're lucky, you might make some money at it as well.