Author Archive

Why and how to pack your textures for iOS/Android

Sunday, December 4th, 2011

Introduction

When I developed Don’t Feed the Trolls on X360 (using XNA), I did not optimize the textures files of the game : the game was very simple, the final hardware (X360) is very fast, so it was not necessary. I arranged the sprites so that I could get their coordinates in-game very easily. Every “troll” sprite for instance is the same size, so most of them are filled with transparent pixels. A lot of space is wasted. Have a look at the sprite sheet for the characters that I use on X360.

X360 Don't Feed the Trolls Characters Sprite Sheet

The characters texture on X360 is 2048×1024. I could easily have it into a 1024×1024 but it was a lot easier if I could have all the sprites of the same kind in a row (for example, all the bear heads are on the top row). I also made a few other sprites sheets for UI, birds, tutorial for instance.

For the first draft of my Android port, I first concentrated on the gameplay and integrate this sprite sheet as is. Of course, I quickly realized I had to spend some time to optimize as obviously, constraints on mobile and X360 are different.

Why packing your textures?

Why is proper texture packing important for games, especially on mobile? Packed textures use less pixels, and from this simple fact, the game is greatly improved in many ways:

Memory

Less pixels takes less memory. Mobile have big memory constraints and saving memory from the ressource is great. Texture ressources are often the biggest ressources.

Loading

There are less files to open, and less pixels to read, this will therefore be faster to load.

Runtime performance

When packing your textures in atlases, more sprites will share the same texture. In runtime, the GPU will then have less textures changes to make and this will therefore speed up your game. This will improve performance if you draw the sprites using the same texture in a row.

It will allow you to reduce your texture sizes. Some Android devices are performing very slowly with 2048 pixels-wide textures.

Game size

The downloadable package size will be smaller too. This is great, especially for people using 3G or with limited bandwidth that won’t download big games.

How to pack?

I first thought of packing my sprites manually but quickly searched for a tool to assist me in that tedious task. There are a few tools available to automatically pack your sprites, and I am currently using TexturePacker, and I’m very happy with it (please note that I got a free copy of TexturePacker from the developer). It’s easy to use and has a lot of functionnalities, such as:

  • Auto-refreshes the packed texture in the tool when I add images to my folders
  • Export in one click
  • Support cocos2d and therefore cocos2d-x which I am using (and many more formats).
  • Removes useless transparent pixels around sprites
  • Efficient packing

All the features are listed here.

Here is a sample of a packed sprite sheet for the Android version of Don’t Feed the Trolls made with TexturePacker:

Packed sprite sheet for Don't Feed the Trolls Android/iOSInstead of 2048×1024, this is just 1024×1024, and most importantly, I have all my characters, the UI elements, and some background elements in the same, smallest texture!

Generic code

I did some code so that resource loading does not have to deal with packs or single sprites. That way, I can send a version without packs to the artist and he can test his ressource live. In cocos2d-x, this is very easy. You first need to load your pack(s) with CCSpriteFrameCache ::addSpriteFramesWithFile( file_name ). And then, read the ressource from the file if it’s not found in the packs. I did it like this:

CCSprite *GetSprite(const char *file_name )
{
 CCSprite *psprite = new CCSprite( );
 psprite->autorelease();
 // Search in the cache, first
 CCSpriteFrameCache *sfc = CCSpriteFrameCache::sharedSpriteFrameCache();
 CCSpriteFrame *psf = sfc->spriteFrameByName( file_name );
 if( psf != NULL )
 {
  psprite->initWithSpriteFrame( psf );
  return psprite;
 }
 CCLog("WARNING : %s not in a PACK!", file_name );
 psprite->initWithFile( file_name );
 return psprite;
 }
sprite->autorelease();
// quite ugly wait to skip dlg/img directory
if( file_name[3] == ‘/’ )
{
CCSpriteFrame *psf = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( &file_name[4] );
if( psf != NULL )
{
psprite->initWithSpriteFrame( psf );
return psprite;
}
}
fgLog(”FROZAX : %s not in a PACK”, file_name );
psprite->initWithFile( file_name );
return psprite;

Conclusion

Packing your textures is very important on mobile platform, but hopefully, great tools make that task very easy and straighforward.

Do you pack your ressources? Do you do it by hand? Which tool do you use?

Follow me on twitterfacebook or google+ for more game development information.

Android Game Development : from Java to C++ (with cocos2d-x)

Saturday, November 12th, 2011

Introduction

In a previous post (here), I was talking about my progress with libgdx, a Java library for Android (and other platforms). Shortly after writing this article, I realized that there is a big disadvantage that I forgot to talk about. It’s so big that it made me stop using libgdx : It is not portable on iOS. I knew this from the beginning but didn’t really think about using anything else than Java. I finally realized that while porting from one language to another is easy, it can take a lot of time.

Cocos2d-x

I searched for multiplatform libraries (Android and iOS). As the game I’m porting (Don’t Feed the Trolls) was developed with XNA, I looked at C# solutions. There is at least one but it’s too expensive. I’ve been doing C++ indie/casual games in the past and I develop in C++ in my day job, so this is the obvious choice. I like the efficiency of languages such as C# or Java (easy to write and debug), but if I want to avoid porting the game another time for the iPhone, I should to use C++. There are quite some libraries in C++ (such as Marmalade). I finally decided to use cocos2d-x. This is a C++ port of the famous cocos2d library for iPhone which is in Objective C. Cocos2d-x has an active community, some multiplatform games have been released already, it’s free and open source. All good stuff!

C++ on Android

I am mostly working using the Windows build of the library but I also did some work on Android. Mixing C++ and Java (using JNI : Java Native Interface) is doable, but really not user friendly. Debugging is terrible, building is slow, you have to install tools such as cygwin, use makefiles (how old school!), and so on. It really does not seem the right solution at first. However, once everything is set up correctly, it’s working fine. Cocos2d-x has good tutorials about this. I develop with Visual C++ 2010 Express on the Windows build, I have all the great tools to debug generic problems. The only real troubles are when you have android-specific bugs in the C++ code but it’s really not frequent. And there are a few ways to debug it with gdb and gdb-server (I never had to use it yet). When you have a crash, there is a very useful tool in the NDK called addr2line (here’s how to use it) that allows you to get the callstack. It’s usually enough to understand and fix the bug. You also can still use old-school debugging techniques such as logging to the output ;) Hopefully, most of my bugs are multiplatform, or in Java code, so I can fix them easily.

Java is still needed

To develop Android-specific code, you still need Java. For example, I use Java for AdMob integration, In-App Purchases or the Facebook SDK for instance. Setting up Java functions called from C++ is not very intuitive, so I opted for a very simple and centralized way: I have one Java function that can be called from C++ with two String parameters. In the Java code, I read these parameters that contains all I need to know to call the specific Java code.

Conclusion

Even though libgdx is really a great lib, after a few weeks working on C++, I’m confident that I made the right choice with cocos2d-x. I did not start developing on iPhone already but it should be quite fast compared to porting Java to C++ (or worse, Objective-C!). I have a working Android version of my game and the performances seems good.

Which language do you use to build your multiplatform mobile games? Do you know other good C++ solutions? Feel free to comment!

Follow me on twitter, facebook or google+ for more game development information.

Don’t Feed the Trolls Sales Stats (Xbox Live Indie Game)

Monday, October 17th, 2011

Don’t Feed the Trolls (try it!) was released on September, 23rd, it’s now time to look at the sales numbers. As of today, I sold 207 copies of the game.

don't feed the trolls sales per day

The sales are better than my first XBL Indie Game (Spring Up Harmony, stats here). However, Spring Up Harmony was initially sold 240 MS Points, and Don’t Feed the Trolls is sold 80 MS Points. Don’t Feed the Trolls was also faster to develop, but art costs were similar to Spring Up Harmony ($500). I need about 750 sales to recover all my costs. I don’t think I will reach this threshold.

Don't feed the trolls Sales per Country

I could recover Spring Up Harmony’s costs with the PC version of the game (especially with the 5 For $5 Bundle). I hope to do the same with Don’t Feed the Trolls, and I’m porting it right now on Android (and probably iPhone later). I think the game is too simple to be sold of PC, but mobile phones are great for this kind of game.

As commonly reported by indie developers, I also don’t find the XBLIG platform very lucrative (but it can be).

Feel free to comment about the game the sales statistics or your own experience. You can also find out more about us on twitterfacebook or g+.

Android Game Development with libGDX

Tuesday, September 27th, 2011

androidAfter selling games on PC, Mac and Xbox 360, I want to develop games on mobile plaforms, and I will start with Android. I chose Android instead of iPhone for two reasons:

  • It’s cheaper: my Mac is a PowerPC and you need a Mac Intel for iPhone development. Also Android phones are cheaper than iPhones.
  • Java is similar to C# : I have C# games ready to be ported to mobile. As Android uses Java, it’s a great platform for me to port those games.

My last X360 game, Don’t Feed the Trolls is a great fit for mobile: quick gameplay sessions and not requiring too much processing power or memory. I therefore decided to port it to Android.

libgdxI started to look for available 2D game libraries on Android and after hesitating between AndEngine and libGDX, I chose libGDX. I will describe here some features and my thoughts about this library.

What I like

Complete API

It’s a simple but complete API. We often see libraries with only rendering support, but with libGDX, you can do rendering (2D and 3D), audio, file management and input (touchscreens). There are also a few useful utility classes and tools (more on this below).

Box2D

box2dThere is also a port of Box2D, the physics library used in Spring Up Harmony (PC, X360). If I ever want to port Spring Up Harmony to Android (probably), the physics part should be easily portable.

Open Source

I like to have access to the source code of libraries I use. I find it reassuring and when debugging, it’s good to be able to step into libraries source code.

Activity

activityThere is currently quite a lot of updates and bug fixes, by the creator of the lib (Mario Zechner) and by community.

Bitmap Fonts

font_small_cropThere is a tool available to create bitmap fonts. This is very similar to the tool I used on XNA (SpriteFont2 Texture Tool) so porting my existing code was very easy.

Desktop Version

If you ever used the Android Emulator of the SDK, you are probably aware that it’s terribly slow and not really usable. I didn’t buy my Android Device yet, but can still work on the game and test it properly because libgdx also compiles for desktop java.

Don't Feed the Trolls for Android running with the Desktop version in libGDX

Don't Feed the Trolls for Android running with the Desktop version of libGDX

Texture Packer

This is another great tool, used to pack many textures in one. I usually don’t care much about texture size and texture memory waste when developing on X360 but this is important on mobile devices due to their limitations. Some features of this tool:

  • Grouping small textures in textures pages (power of two).
  • Strip transparent pixels on the borders of textures. This required quite some tweaks and update in my own fgDrawSprite class and rendering functions to manage properly, but this is really a great way to save memory and disk space.
  • Has an incremental option to avoid generating everything when updating only some resources.
  • Can be called from the game itself in the desktop version. A good practice is to automatically call the packer in the desktop version, and use the generated assets in both Desktop and Android.

This is really a time saver tool.

What I don’t like

Lack of documentation

There is no good and centralized documentation. You need to look for information on the forums, in the source code and/or on blog articles. Due to the activity of the library, I sometimes find out that I’m using old stuff that is not supposed to be used, because it’s deprecated and has been replaced by something else. The parameters of some API functions are not always properly documented too. For instance, I had trouble using a rendering function and found out that the rotation parameter was an angle in degrees (it’s usually in radians in the libraries I used before).

Reverted Y-Axis

coordsI found this very strange but in all the 2D APIs I used, the coordinate system used the point (0,0) as the top-left corner, with X going right and Y going down. In libgdx, the Y axis is going up, and the 0,0 is bottom-left. I had to change some rendering functions to take this into account.

Android Specific

Doing Android specific code is not very clean because the lib is supposed to work on desktop and Android. I guess this is also because of Java, and I wished we could have some preprocessing to condition Android specific code. There are many workarounds, because the Android application overloads the Desktop application. So you can create empty methods on Desktop that are overloaded only in the Android project with Android specific code. I hope this won’t get too messy when I’ll work on very specific and touchy stuff such as in-app purchases.

What I don’t know

Performance

I don’t own an Android device yet and did not test other API, so I can’t really talk about the performance of the API. According to users, it is faster than most other APIs.

Conclusion

Using libGDX is a good and easy way to start developing Android games. For now, I’m happy with this library and you can see on the screenshot above that development is going well. I will probably release a few games with it.

If you tested different Android libs or have anything to add, feel free to comment about it.

You can find out more about Frozax Games or me on twitter, facebook or g+.

Don’t Feed the Trolls available on Xbox Live Indie Games!

Friday, September 23rd, 2011

I am proud to tell you that my last game Don’t Feed the Trolls is now live on the XBLIG market. Here is the trailer:

Please download the game on the marketplace and tell me what you think about it!

As usual, I’ll post sales figures in a few weeks/months for the curious.

Have fun slapping trolls!

5 for $5 Bundle and Spring Up Harmony Statistics

Thursday, July 21st, 2011

As you probably know, Spring Up Harmony was in the 5 For $5 Bundle (also called buygamesnotsocks). You can read a full postmortem of the bundle on Jorge Rodriguez’ blog. With data gathered from my leaderboards, I made a few statistics (I love stats ;) ). Though the bundle sold 3,642 copies, I have (only) 1,139 “bundle players” on the leaderboards, but new bundle players are still appearing every day.

I will show you four graphs.

Levels completed per day

The first graph is showing the levels completed per day. Note that the bundle went out on June, 22th, and ended on July, 3rd.

graph1

The days are based on GMT, therefore, on the graph the bundle went live at 6pm. The first full day is June, 23rd. Today, I still have about 4 to 5 times more players than before the bundle.

Activity of the game depending on the time of day

The second graph shows the activity of the game depending on the time of day.

graph2

This time, I converted the graph to be based on Pacific Standard Time (USA West Coast). I didn’t put numbers on the vertical axis because it’s just meant to show variation of players throughout the day.

Nationality of the players

The third graph shows the nationality of the players.

graph3

The results are not really a surprise, especially since the bundle was in English and news sites writing about the bundle were mostly all american websites. There are players from 47 different countries.

Number of levels completed per player

This fourth graph shows the number of levels completed per player. The game has 35 levels.

graph4

I’m happy that many players completed the game. I tried to find a reason to the spike of players doing 9 levels but could not find any. I don’t think the 10th level is that terrible ;)

Conclusion

I am really happy that this bundle gave the opportunity to people to play Spring Up Harmony. Many players would never have heard of it without the bundle. And I also think some players bought the bundle because of some other games but took the time to try them all.

I’ll use this article to thank to all the great developers involved in the bundle, and especially Jorge who organized it very well!

Feel free to comment, and follow me on twitter, facebook or google+.

5 For $5 Bundle is LIVE!

Wednesday, June 22nd, 2011

logo

Today, four indie game developers and Frozax Games launched a new bundle : 5 Games for $5, check out the trailer:

The games are:

These are all great games, try them now and support indie developers! The website is here and you can buy a bundle here!

Please spread the great news on twitter and facebook!


Achievements/Rewards statistics for Spring Up Harmony

Sunday, June 12th, 2011

Spring Up Harmony PC was released a few months ago, it’s now a good time to study statistics of the rewards (or achievements) of the game. Rewards are a good way to see what the players are really doing in the game.

These are the stats of online players that played the full version of the game. To have more data, I also used data from pirate players. Pirate players do not appear in the leaderboards, but I still log their achievements. I consider a player has the full version (legally or not) when he has played a level not included in the demo.

I sorted the achievements according to the percentage of players having it.

beginning

Beginning

Complete the first level of the game.
100%
beginning

Two in One

You hit two Harmony objects in one shot.
100%

Five

You completed five levels.
99.8%

All Clean

You removed all the objects of a level.
83.0%

Bronze Medal

Your global score is 500,000 points.
82.6%

Just in Time

You completed a level with less than ten seconds left.
65.1%

Catcher

You caught 500 objects with the bucket.
55.4%

Silver Medal

Your global score is 1 million points.
47.5%

Fast

You completed a level with seven shots or less.
38.0%

Shooter

You shot 500 balls.
35.4%

The End

You completed all the single player levels.
19.9%

Gold Medal

Your global score is 2 million points.
17.9%

Top Scorer

You scored 200,000 points in one level.
16.5%

Addict

You played for 5 hours.
2.9%

Multiplayer

You played ten multiplayer games.
1.2%

Another stat not shown above is that no player have all achievements.

The main thing to learn from these stats is that I probably spent to much time implementing the multi-player mode. It was not that long to develop but more levels would have been better. It’s probably because it’s only multi-player on the same screen and not online. The achievement “Two In One” seems too easy. Maybe it should have been “Three in One”.

Players, do you like achievements?
Developers, do you also log the achievements of your players?

Feel free to comment and follow me on twitter and facebook.

Useful C# and Visual Studio tips you might not know

Tuesday, May 31st, 2011

While working on my next game, I tried to keep notes of interesting tips I used. They are related to C# and Visual Studio.

Overriding ToString()

When debugging or prototyping, you often need to display complex objects on the screen on in the debugger output. A handy way to do this when dealing with complex classes is to override the ToString() member. Here is an example:

class ComplexClass
{
   int _number = 0;
   string _string = "My String";

   public ComplexClass( int n, string s )
   {
      _number = n;
      _string = s;
   }

   public override string ToString()
   {
      return String.Format( "{0} / {1}", _number, _string );
   }
}

ToString() is also used by the debugger in the Watch dialog.

?? operator

I discovered the ?? operator a few months ago. I don’t use it much but could be useful in some cases. It allows you to replace the following code:

if( a != null )
   b = a;
else
   b = c;

by

b = a ?? c;

New class template

When you create a new class (using the right-click on the project, Add, New Item…), the file created is not empty but already has a template and a few using statements. You can edit this template easily. For instance, I added a “using fg;” with my own game library to this template. The template is found in the Visual Studio directory: {Program Files}\Microsoft Visual Studio 10.0\Common7\IDE\VCSExpress\ItemTemplatesCache\1033\class.zip. There are templates for anything and you will probably want to edit a few of them.

new does not always allocates

In C#, even when using the new operator, you might not allocate memory. For instance, the following line:

Vector2 point = new Vector2( 10, 20 );

does not allocate memory, because Vector2 is not a class, but a structure. The rule is as simple as that: a class allocates memory (and returns a pointer) and a struct does not allocate memory. It’s simple, but often misunderstood, especially if you come from C++.

Add As Link source file

Recently, I re-used source files from a previous project for a new one. I used the Add Existing Item option but Visual C# creates a copy of the source file in the current project directory instead of referencing the old file. I want to reference the old file so that it can be modified in both projects. To avoid that, you must select the hidden Add As Link option, by clicking the small arrow next to the Add button of the dialog box.

add_as_link

Overloading the [] operator

I often have objects containing a list of items. For instance, in Spring Up Harmony, I have a Ball Manager used to manage and draw the balls. I found it very handy to overload the [] operator to access elements of the list inside the manager from the outside directly.

List<Ball> _balls = new List<Ball>();
public int Count { get { return _balls.Count; } }
public Ball this[int i] { get { return _balls[i]; } }

That’s it!

I hope you found some of the tips useful!

Feel free to share more tips in the comments!

Follow me on twitter or facebook to get notified of new posts.