KoboldTouch brings you the best 2D game development experience for Apple’s platforms!
KoboldTouch is the only Objective-C, ARC-enabled 2D game engine built on the Model-View-Controller (MVC) design pattern. Write ambitious games with greater ease!
KoboldTouch is also a continuously evolving, customer driven game development framework for iOS & Mac OS X, designed by game industry veterans to incorporate game development best practices and decades of experience.
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.
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).
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.
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.
I'm Steffen Itterheim, author of Learn SpriteBuilder and the (not outdated) Learn Cocos2D book series.
I started my game industry career in 1999 creating Gameboy titles as designer, followed by working as software engineer on RTS/RPG series SpellForce and BattleForge for a studio that was acquired by EA in 2006.
Since 2010 I'm a freelance developer, specialising on 2D game development for mobile.
Try out TilemapKit!
TilemapKit is the complete solution for tilemap game developers. Click an image to learn more!
Iso Map rendered by TilemapKit
Ortho Map rendered by TilemapKit
Hex Map rendered by TilemapKit
Steffen's Books
The iOS Action RPG Engine
Rapidly create your own RPG or action-adventure game with this complete starter kit. Includes an ebook, game source code and a royalty-free art package. More Affiliate Products …