I’m currently completing one last contract project. One of the last things I had to deal with was to optimize the game’s memory usage.
In today’s iDevBlogADay article I’ll explain how I was able to cut down memory usage by about 25-30 MB (down to 90-95 MB, ie fixing memory warning related crashes) as well as reducing the size of the app bundle from around 25 MB to below 20 MB (which would have been more awesome if Apple hadn’t already increased the over-the-air download limit from 20 MB to 50 MB some time ago).
I’ll also explain how to animate the loading screen while you’re loading resource files, and I’ll add some best practices and common wisdom too.
What’s using 90% of the memory?
Take a guess.
In almost all cases, it’s textures that consume most of the app’s memory. So textures is where you look to optimize first and foremost if you’re having memory warning troubles.
Avoid loading PNG/JPG Textures one after another
The problem with texture loading in cocos2d is that it happens in two steps: first, a UIImage is created from the image file. Then a CCTexture2D object is created from that UIImage. This means while a texture is being loaded, it will consume twice as much memory for a short time period.
The problem used to be so bad that if you loaded 4 textures one after another in the same method, at the end of the method each texture would still consume twice as much memory as it ought to, probably because of the way autorelease works.
I’m not sure if this is still the case, or whether this only applies to manual reference counting but not ARC. I made it a habit to load textures in sequence, waiting at least one frame before trying to load another. This will allow any texture loading overhead to be released from memory. Besides, as you’ll see later, if you want to load textures and other assets in the background this asset-load-sequencing is something you’ll do anyway.
Since I’ve started to offer KoboldTouch developers have been wondering what will happen to Kobold2D? I’ll answer these questions here.
When cocos2d 2.1 (stable) is released, I’ll update Kobold2D to include this latest cocos2d version. Same with any other cocos2d version that will be released in 2013. I won’t update to beta versions – sometimes they’re riddled with bugs, other times the next beta comes only a week or two later.
I’ll continue to support and update Kobold2D for as long as there’s interest in it but I’ll definitely focus my efforts on KoboldTouch now.
Sometime in 2013 (probably not before Q2) I’ll release KoboldTouch “Lite” for free, with limited features and support. This Lite version will then take over as the successor of Kobold2D, while Kobold2D will remain available for some time.
KoboldTouch “Lite” will have the MVC framework but not much else. It will not include any additional features such as OS integration, better tilemap rendering, Box2D Objective-C wrappers and what not.
This ought to help developers get accustomed with the MVC framework.
Relaunch of www.kobold2d.com
Sooner or later I’ll relaunch the www.kobold2d.com website as www.koboldtouch.com. I’ll go for a simple look & feel (KISS), it will include the Kobold2D articles and I’m going to write all KoboldTouch documentation publicly.
For one this will make it easier for me to write and publish documentation. It should also help KoboldTouch’s popularity to reveal its documentation to both developers and search engines.
KoboldTouch compatibility with Kobold2D
KoboldTouch is not 100% compatible with Kobold2D, since I’ve already trimmed the less popular libraries from KoboldTouch: Chipmunk, Chipmunk Spacemanager, Cocos3D, ObjectAL, SneakyInput, iSimulate, AdMob. The remaining libraries are: cocos2d-iphone, cocos2d-iphone-extensions, CocosDenshion, Kobold2D, Box2, Lua and a few smaller additions (BitArray, LOG_EXPR, etc).
You should be able to port code that does not use one of these libraries with ease. Though without adapting to the MVC framework you lose a lot of the benefits of using KoboldTouch.
Custom Folders and Source Control
Issues regarding custom folders and source control usage come up frequently. I will alleviate those with KoboldTouch.
The project starter tool will be improved to support creating new projects in a custom folder, with or without copying the offline documentation to the new folder. The project upgrader tool will also work with custom folder locations.
The documentation accounts for most of the disk space usage of a Kobold2D/KoboldTouch project and should therefore not be included when you intend to manage this project with source control. Specifically if it’s an online repository with limited disk space. With the additional libraries stripped and documentation not included, a new KoboldTouch project weighs in at around 15 MB of disk space.
What will remain is that the installer will install to a fixed folder, since you will then be able to create new projects in any custom folder so there’s no real need for a custom folder location during installation.
There are plenty of issues with PackageMaker to overcome to support custom folder locations and I’d rather spend that time on other things. As was always the case, you can of course move the Kobold2D folder anywhere else after the installation completed – it’s just one click & drag operation in Finder.
Your question not answered here?
Let me know by writing a comment.
For the past two weeks I’ve been running a Cocos2D Developer Survey. As of today, 236 developers started the survey and 189 finished it completely. That’s 80% despite the many questions they had to answer.
Here are the results with my observations. I started the survey also to see if I was on track with KoboldTouch, and whether certain assumptions hold true. Specifically I had a hunch that cross-platform development is only perceived to have great value or appeal. Let’s see if I was right.
Click on each image for full resolution.
Who are you?
I was very curious how many cocos2d developers consider themselves to be hobbyists and indies compared to professionals, who either work for a mobile developer or are taking on freelance jobs as one.
Almost half of those who answered the survey are hobbyists. Nearly 30% consider themselves indies who make a living making mobile games. This is great! Continue reading »
Continue reading »
This year’s Line-Drawing Game Starter Kit Xmas sale starts early and runs for two months until January 7th, 2013. You can have it for $49.50 instead of $99 – 50% off!
But there’s a catch: the XMAS2012 coupon code has only 100 uses! Act fast before it’s used up.
Site License! Unlimited Apps!
Royalty Free! No Attribution!
60 day money-back guarantee!
Made with the popular cocos2d-iphone game engine.
Compatible with cocos2d-iphone v1.1 and v2.0, and iOS 6.
Includes ARC enabled versions of the starterkit!
XMAS Sale – 50% off – only $49.50
Enter: XMAS2012 as coupon code.
Coupon code limited to 100 uses. Act now!
It’s only a start to better explain how KoboldTouch compares with cocos2d-iphone.
I’m now working on a KoboldTouch mini-game to showcase the KoboldTouch workflow and features. It’ll be the basis for the KoboldTouch Introduction Tutorial.
I’ll post a video presentation of the project and key points once it’s done. If you’re interested you can follow KoboldTouch development via PivotalTracker.
The mini-game project is also very important to “eat my own dogfood”. Even just a simple game made several things that didn’t feel right obvious, and presents opportunities for improvement.
I’m happy that the KoboldTouch users requested this simple game tutorial.
Speaking of members: leaving aside the initial 2-day launch rush, on average two new members sign up every day.
If KoboldTouch continues to grow at this rate, it will have 100 members before Xmas! That would be a major milestone I did not expect to achieve before February/March!
You can help KoboldTouch by taking 5 minutes of your time to complete the Cocos2D Developer Survey. I’ll post the results in a week and what they mean for KoboldTouch.
I recorded two insanely great, beautiful, amazing, wonderful (I’ve been watching Steve Jobs’ keynotes recently, it must be rubbing off a bit) feature presentations to explain two cool features in KoboldTouch.
Weak typing allows you to create, read and assign variables just by name. You don’t have to declare the variable, just assign a value. No need to change the interface, and works with all KTModel classes.
Access is almost as fast as property access, and the values are mutable thanks to the KTMutableNumber implementation which feels like NSNumber except that it doesn’t create and release new objects every time you need to change a value.
It’s hard to find the right words to describe the launch of KoboldTouch. I can’t think of anything else but WOW! right now.
I can’t wait to hear what you have to say about KoboldTouch, and then act on your feedback.
For those who were just waiting for the launch:
Sign up on the KoboldTouch product page to get access to KoboldTouch and Essential Cocos2D.
The rest of this post is a summary of what I wrote before on these two-products-in-one. Actually, I think of KoboldTouch & Essential Cocos2D as being much more a service than products. And it’s a full time commitment from myself.
This calls for music!