Xcode 4 Debugging Crash-Course
|
|
What do you do if your app doesn’t behave as it should, or even crashes?
Answer A: Post your problem in just about every programming forum.
Answer B: Use the Xcode Debugger to analyze what’s going wrong.
Since most of you already know how to do A I’ll focus on B in this Xcode 4 Debugging Crash-Course. It’s kind of aimed at beginning Xcode developers but that’s just because I hope – against better knowledge – that experienced developers already know that … thing … that debugger stuff. Ya know?
From Dogfooding to Catfooding
|
|
Most developers have heard of the phrase “Eat your own dog food”. It refers to the habit of actually using what you’re creating.
A typical example would be a company building Yet-Another-Issue-Tracking-Tool™ while using said issue tracker to manage their Yet-Another-Issue-Tracking-Tool™ project. And you’ll surely have heard of a game engine that was initially only developed as a necessity to build a game, then polished and released to the public to great success, while the developer continued to create games with his own engine.
Dogfooding is considered a good practice, actually a best practice. You know that the tool you’re building works, and that it satisfies your needs.
But “your needs” is also the achilles heel of dogfooding, and it’s just a small step away from forever “perfecting” your product (known as “gold plating”). So sooner or later, you’ll have to do some catfooding, too. Meaning: to feed the user’s needs. Continue reading »
|
|
Kobold2D is about solving annoying, recurring problems, or simply making all things Cocos2D more convenient. The new KKInput class does both! (*)
Linkvent Calendar, Day 19: Cocos2D Programming Tutorials
|
|
Tutorials for Cocos2D for iOS are a plenty on the web. But I managed to find one that’s not very well known and provides a more technical introduction to the Cocos2D concepts and how to program menus, animations and detecting collisions. By technical I mean that the focus is clearly on providing working code.
Written by Hans Hamm the Tutorial Programming iPhone Games with Cocos2D is divided into four parts:
- Part 1 – Cocos2D Architecture Overview
- Part 2 – Buttons & Menus
- Part 3 – Sprite Animations using a Texture Atlas
- Part 4 – Scheduling updates & detecting collisions
Hans is also a co-founder of Anima Entertainment, they created the iPhone games Crash Birds (free) and Earth Defender:
Linkvent Calendar, Day 13: Balloon Ride Postmortem
|
|
Today’s Linkvent Calendar entry comes from David Sutoyo. His second Cocos2D game, Balloon Ride, was published on the App Store on Dec 1st. David took some time to write a postmortem about making Balloon Ride. He starts out by saying that programming in Objective-C is hard, game design is even harder but marketing is the hardest part. However, he concludes that the overall design process is fun and he is now toying with the idea of using Corona because programming in Lua is simpler than Objective-C.
David also wrote a mini-postmortem about his first Cocos2D game Memory Flash.
Watch the Balloon Ride gameplay video:
What? You were afraid to ask everything you wanted to know about game programming?
|
|
Regardless, this may be the answer. Or as close to it as any publicly shared link list not hosted on link aggregator sites could ever be. I’m talking about Amit Patel’s Game Programming Information pages. There’s something for everyone, but specifically a lot of articles about pathfinding, AI and tile-based games including procedural world generation.
Prefer Composition over Inheritance
|
|
When the question came up whether to subclass CCSprite or use some model class to build your game entity hierarchy in the cocos2d forum, i stressed that one should try not to use inheritance and keep the inheritance hierarchy to as few levels as possible. I’ve worked with codebases with hundreds of thousands of lines of code, and hundreds of different types of actors in the world. Yet the inheritance hierarchy was 2 super (parent) classes for almost all objects, only very few game objects had 3 or 4 super classes. How can you make complex games this way?
The answer lies in composition, often referred to as Game Components by engines like TorqueX and the PushButton Engine (a Flash game engine from the original Torque developers). This video from the PushButton lead developer Ben Garney explains it very well and also illustrates the problem with inheritance over-use in game engines. Something that most developers new to object-oriented and/or game programming do in fact tend to over-use – i blame that on poorly written books and other introductory OOP sources which emphasize inheritance without discussing its disadvantages.
You can read more about PushButton’s Components system in their documentation. How they implemented Components in TorqueX and what the differences are to XNA Game Components further enhances understanding of the concept.
For further reading and arguments read the Wikipedia article on component based software engineering. As a matter of fact, the Objective-C language was invented to be able to create re-usable software components!
Scott Bilas’ GDC 2002 talk about A Data-Driven Game Object System (PDF) as used by Dungeon Siege contains more pointers on why inheritance fails for game developers and what the advantages (but also some caveats) are with component-based game engines. The talk may be old but it’s still as valid today as it was back then. In fact, in 2002 i started working on SpellForce which already had a component system built into its core, called Aspects, Abilities and Spells. It allowed us to enter all the game data in the database and programmers only needed to write the generic code that dealt with the data, as well as setting certain limits and validity checks (eg. you couldn’t use a damaging spell on yourself but if you wanted to you could target enemies with your heal spell, or have archers shoot buildings … errm).
During GDC 2009 a similar presentation was held by Radical Entertainment’s Marcin Chady. The talk was called Theory and Practice of Game Object Component Architecture (PPT).
Mick West wrote an article Refactoring Game Entities with Components which describes the challenges and benefits of changing the Tony Hawk codebase from an inheritance model to a game component system.
A somewhat more advanced read on component use is a collaborative paper called Dynamic Game Object Component System for Mutable Behavior Characters which talks about components in context of finite state machines and NPC behaviors with a rule-based activation system.
The Game Architect blog calls it an Anatomy of Despair and sums up very good what the cons of inheritance-based class design is and how composition solves them.
Article Collection
|
|
The information on this page may be out of date!
I compiled most of this list in 2009 or maybe early 2010 (don’t remember exactly). Do expect some broken links and out of date information. I’m no longer updating or maintaining this page, I leave it here only for reference.
cocos2d for starters
The cocos2d homepage – this should be obvious but since most people land on the google source code repository page for cocos2d iPhone instead of the real homepage www.cocos2d-iphone.org i wanted to post it here. Usually the most noteworthy threads from the forum as well as important blog posts by others are posted on the blog, and of course any new releases and updates to cocos2d.
cocos2d iPhone documentation – a post on the official website explains where you can find what kind of documentation.
Things i wish i knew when i started with cocos2d – Troubleshooting, Tips & Tricks for everyone
Ray Wenderlich (formerly Mythic Entertainment) posted a great tutorial on how to make a simple iPhone game with cocos2d. Take a look around at his website as he keeps writing new tutorialistic articles such as creating buttons in cocos2d and an intro to the box2d physics engine which is also part of cocos2d.
Introduction to 2D game programming with cocos2d iPhone
The cocos2d iPhone programming guide in the cocos2d Wiki.
Introduction to cocos2d iPhone visual effects (aka Visual FX).
Apple’s excellent Objective-C Programming Language reference (PDF)
Open GL ES 1.1 reference – only needed if you intend to do OpenGL programming – you don’t need to know about OpenGL if you’re using cocos2d but it may come in handy sometimes.
As for books, i can NOT recommend iPhone Games Projects by Apress. Repeat: not recommended! It’s a badly written collection of blog posts about the kind of games most game developers would not want to make (chess etc). It does not contain particularly good or reusable examples of code and the choice of projects is questionable to say the least. It has generally very little value for a cocos2d iPhone developer as all examples are either written in Cocoa Touch or plain OpenGL.
cocos2d, Cocoa and Objective-C code fragments
Have a look at my proposed CCDirector drawScene method which redraws the screen anytime you may need to.
Blog Post: efficiently reusing Default.png for landscape mode – Note: Ricardo has since integrated this in Sapus Tongue source code.
Integrating other APIs into a cocos2d application or game
First of all, here’s a tutorial on how to integrate the cocos2d API reference into Xcode.
Integrating Facebook Connect with cocos2d. See also the forum post for the user comments. In addition watch this video about adding Facebook Connect to your Xcode project since the necessary steps aren’t covered in the integration tutorial. And once again, Stackoverflow strikes with an excellent link collection for Facebook Connect iPhone developers.
Integrating AdMob with cocos2d iPhone Applications
Integrating OpenFeint with cocos2d iPhone Applications
Integrating Agon Online into cocos2d iPhone
Combining SIO2 with cocos2d, with source code
SpaceManager – an Objective-C wrapper for Chipmunk
There are already ports for cocos2d iPhone, one focuses to port cocos2d iPhone to Mono .NET using C# and the other cocos2d port is Java-based for Android development.
Generally useful tools & knowledge for cocos2d iPhone developers
How to handle device orientation and how to implement autorotation for a cocos2d app or game.
A list of editors useful for cocos2d development is described on the cocos2d’s homepage blog in two parts: part one and part two. It includes tile editors, Texture Atlas and Bitmap Font generators.
Ernesto’s pseudo-code on Pixel-Perfect collisions. It was hard to find and others seem to have problems finding it as well yet people already know it as “Ernesto’s post”, so it deserves a mention here. In this forum post is one implementation of pixel-perfect collision code and here is another implementation of pixel-perfect collisions. Finally we learn about the intricacies of endianness in pixel data, meaning how pixel data changes depending on the platform (iPhone vs Mac).
Zwoptex Texture Atlas tool for use with cocos2d iPhone (and probably others)
Finding memory leaks using the CLANG static analyzer. Don’t leak memory. That’s terrible. Read how you can run a program that tells you with impressive accuracy where there are memory leaks in your code, at least potential ones. Make sure you also read the comments further down since they contain more command line samples that fix some issues for iPhone OS 3.x among other things.
How to obtain the iPhone crashlogs from your beta-testers and costumers. And then there’s Apple’s manual on how to debug crashdumps. In short: always compile both debug and release builds at the same time, then keep both dSYM files and make sure you can later identify to which version and build they belong to. It’s easiest to use source control here and simply flag or label the version you used to create distributed Ad-Hoc or App Store versions with.
iPhone Apps can be opened via URLs that also allow passing what some might call “command line arguments”. Here are a few websites that document those URLs for various apps: URL schemes for various iPhone Apps, then there’s the handleOpenURL: website and finally AppLookup.com.
Specifically for linking to the App Store you will find Apple’s iTunes Link Maker useful. On Stackoverflow you can learn how to create links to your App that you can send via email. And finally, this Ars Technica article covers all the finer details of creating an App Store link that works for the iPhone’s App Store, including opening the App Store app with a search term – which is the only way to show all the apps of a particular company or developer on the iPhone’s App Store.
8 confusing Objective-C Warnings and Errors explains some of the more confusing things Xcode (actually: GCC) throws at you and leaves you wondering. After reading this article you’ll know what you’re dealing with the next time it comes up.
Provisioning Profiles Gotchas – we all have one of these issues sooner or later (or frequently).
App Store Rejection reasons – be sure to go through this checklist before submitting your App to iTunes Connect to avoid your App being rejected due to some commonly made mistake or oversight.
How to build an IPA file from Xcode shows you how to setup a build target in Xcode that will output an IPA file. Those are very helpful for Ad-Hoc distribution of your App, as IPA files do not get as easily mangled (leading to errors such as “resources have been modified”), especially on Windows machines. It also makes installing Ad-Hoc builds easier since a simple double-click suffices to open iTunes and install the App. Plus it’ll have a proper icon in iTunes’ Application folder.
How to properly set your App’s iTunes Release Date and the things to watch out for. If you’re about to release an App you must read this otherwise you risk your App not being listed on the “What’s New” list.
How to calculate the App Store size of your iPhone App before approval. It’s not magic nor random, it can actually be calculated to within a rather small margin of error. The good thing is, the error will be that the calculation gives you the maximum size your App could possibly have on the App Store. With experience you’ll learn how good your Apps compress after approval, and that depends highly on the game engine used. Unity is hit especially hard by this, typically Unity apps get added another 4-5 MB to the zipped App you’re uploading, in some cases even more.
How to set and change the list of supported languages in iTunes: according to this post on Stackoverflow all you need is one localized file. What i do is, under Resources, i add a new .strings File and leave it empty. Then right-click, choose Get Info and on the General tab click “Make File Localizable”. Then go back to the General tab and click “Add Localization” until you’ve added all languages your App supports. Note that you do not have to reference or otherwise use that file in your code – it just needs to be there. If you look into your App Bundle (right click: Show Package Contents) you’ll notice that new folders like English.lproj, German.lproj etc. exist. Those are scanned by iTunes to create the supported languages list.
How to change an App Icon’s name depending on the iPhone’s language setting. While we’re at it you can also learn how to figure out more quickly if a specific name still fits under the App Icon without being shortened.
My iPhone & iPad Design Templates for OpenOffice Draw
Open Office Draw Templates for designing iPhone & iPad games. They offer you a canvas to create the visual elements of your game and pitch your ideas. I use them to pitch my ideas or create concept drawings of iPhone/iPad apps and games.
You can either use Open Office Draw to draw on them, or just print out the images and draw on it. Both versions have at least one image where the screen background is white, so you can easily draw on it. The iPad version also has a vector graphics representation, so if you worry too much about the completely dark space for printing – turn it into light gray or even transparent with just the border lines shown.
Download the iPhone Design Template for OpenOffice Draw.
Download the iPad Design Template for OpenOffice Draw. For the iPad i took extra-care to scale the images to close to original size, and i also recreated the iPad as vector graphics in almost exact original size.








