The most frequent questions I get from readers of my Learn Cocos2D book:
- “Where can I download the source code?”
- “Why do I get compile errors in CCLabel?”
- “Is there an updated version of CCAnimationHelper?”
They all boil down to the fact that the book was written against cocos2d-iphone v0.99.5 with some projects using v0.99.4 and a few even had used v0.99.3.
Unfortunately this is also why some readers deducted one or more stars in their Amazon book reviews. Even more unfortunate because the changes that break the code were entirely cosmetic (renamed classes, function parameters removed or re-ordered, deprecated functions in favor of others). All changes required only fixing the lines using one of these outdated classes (CCLabel, CCLayerColor) or functions (bitmapFontAtlasWithString, frameWithTexture, …).
Quick List of Changes
I kept track of the changes I made to the source code. This is what it boils down to:
- remove: EAGLView viewWith… -> remove last parameter: preserveBackBuffer:NO
- remove: CCSpriteFrame: frameWithTexture -> remove last parameter: offset:CGPointZero
- remove: CCAnimation: animationWithName -> animationWithFrames & remove last parameter: frames
- rename: CCLabel -> CCLabelTTF
- rename: CCBitmapFontAtlas -> CCLabelBMFont
- rename: CCBitmapFontAtlas: bitmapFontAtlasWithString -> labelWithString
- rename: CCXxxxxTransition -> CCTransitionXxxxx
- rename: CCColorLayer -> CCLayerColor
- rename: CCQuadParticleSystem -> CCParticleSystemQuad
- rename: particle system: centerOfGravity -> sourcePosition
- change: particle system: use NSUInteger instead of int for initWithParticleCount
These are the changes affecting the book’s source code. There were some more changes in the cocos2d-iphone engine, for example some actions have been renamed as well.
Good News: Updated Source Code for v1.0
I updated the book’s source code to use cocos2d-iphone v1.0.0 rc2. Once the v1.0 final is released I’ll make another update.
You can get the book’s source code from the Learn Cocos2D Book product page (scroll to the bottom), or via this direct download link. The download is about 100 MB and contains all the chapter’s source code plus some extra projects not mentioned in the book, and all of them (over 70!) are now using cocos2d-iphone v1.0.
Note: This code obviously differs slightly from the code described in the first edition of the Learn Cocos2D book, so you should get the unmodified v0.99.x book source code as well.
Upgrading to Cocos2D v1.0
I also recently wrote a tutorial outlining the steps to update an existing cocos2d-iphone v0.99.x project to v1.0 in case you have an existing project that you’d like to upgrade to the latest Cocos2D version.
Learn Cocos2D: Second Edition
All these changes will be reflected in the second edition of the Learn Cocos2D book.
The second edition will be released summer 2011, likely around July to August. This is my estimate based on the fact that my work is scheduled to be completed on June 27th, and I’m working hard to keep that (tight) schedule.
Actually, make that we are working hard. The second edition of the Learn Cocos2D book will have contributions from a co-author. Someone who is well-known in the Cocos2D community! To be unveiled.
Does he need any introduction? I guess not but on the off-chance that you’ve managed to have an interest in Cocos2D but haven’t heard of Ray’s Cocos2D tutorials, you should check them out.
Upgrading cocos2d-iphone is a recurring issue for many developers but since it happens so infrequently during the lifecycle of a project, there’s just no routine to follow. Eventually you might want to upgrade cocos2d-iphone, so the question arises: how do you do that with the least amount of trouble?
As I’m going through the process of updating over 70 (!) Xcode projects for the second revision of my Learn Cocos2D book, I thought I should outline the steps to upgrade an existing Xcode 3 project which uses cocos2d-iphone v0.99.x to a Xcode 4 project that uses cocos2d-iphone v1.0.x.
Prerequisites: software update
Obviously, you want to download the latest cocos2d-iphone version and unzip it to any directory. Just remember where you unzipped it because that’s where you’ll copy the new library folders from.
You also want to make sure you’ve upgraded to Xcode 4 by now, by installing the iOS 4.3 (or later) SDK, if you haven’t done so already.
Caution: Make sure Xcode is closed during the first steps.
Step #1: delete libs folder contents
In your project’s folder, in this case DoodleDrop03, select all folders in the libs folder and delete them without mercy:
You’ll end up with an empty libs folder. In other words, don’t delete the libs folder itself or in case you did, make sure you re-create the libs folder.
Caution: The reason why I delete all the libraries in the libs folder instead of simply overwriting the libraries with new ones is simple: you can expect the updated cocos2d-iphone version to have removed or renamed some files. By first deleting all libraries you can be sure that no “zombie files” exist which are no longer used but might still be compiled when you later re-add the libraries. Such zombie files would screw up the build process and generate errors like “Duplicate defined symbols” and other such mishaps.
Step #2: copy the library folders
The first thing you’ll notice when you want to upgrade the libs (Box2D, Chipmunk, cocos2d, CocosDenshion, cocoslive, FontLabel and TouchJSON) is that they’re in different folders in the cocos2d-iphone project that you’ve downloaded and unzipped.
Make sure you select the exact same folders that are selected in the screenshot below:
This difference in folder layout can be a bit confusing. What you need to be aware of is that the Box2D, Chipmunk, FontLabel and TouchJSON folders are in the external folder in the cocos2d-iphone project. Furthermore, the Box2D folder that you should copy is a subfolder of Box2d. Note the difference in capitalization of the letter D. You want to copy the folder with the uppercase D: Box2D. The same goes for the CocosDenshion folder, you should select the CocosDenshion folder inside the CocosDenshion folder.
Caution: Make sure you don’t select the Box2D Testbed folder – if you do and copy that as well, Xcode 4 might lock up building the project, consuming 100% CPU power and requiring a force quit to shut it down.
Note: If you use only Chipmunk or Box2D physics, or neither of them, you can skip copying these folders of course.
To complete the copy opertation, go to the libs folder and paste the copied library folders so that you end up with a libs folder that looks exactly like the image in Step #1.
Tip: If you prefer drag and drop you can just drag the selected folders from one Finder window to another onto your project’s libs folder. This may be easier to do but you should remember to hold down the Option key while dropping so that you actually copy the folders instead of moving them. The copy operation is indicated by the green + icon underneath the cursor as you drag & drop while holding the Option key.
Step #3: Remove Library References
Open your project in Xcode 4 now.
Select all groups under the cocos2d Sources group and hit Backspace to delete these groups (or right-click and choose Delete). You will be prompted with a dialog like in the screenshot below.
Make sure you select the default option Remove References Only to avoid deleting the new library folders you just copied:
Once you’ve removed the libraries groups, the cocos2d Sources group should be completely empty. You just got rid of all the old references, saving yourself from any potential compilation errors caused by references to files which may not exist anymore.
Step #4: Add Library Folders
Next you want to re-add your library folders. Select and right click the cocos2d Sources group and select Add Files to “NameOfYourProject”…:
Browse into the project’s libs folder and select all the library folders that you need in your project.
You may have noticed that my project doesn’t use any physics engine, so I decided to not add them here. If you do use Box2D in your project you would want to also select Box2D of course. Likewise if you use Chipmunk.
Note: While it’s not a problem to add both physics engine folders, doing so might increase your App’s size.
Now, here’s where you need to be careful with the options! You want to make sure they’re set exactly as in the screenshot below. Most importantly, when adding files Xcode will default to add the files to the project’s main target (in this case DoodleDrop) instead of the cocos2d libraries target.
Make sure that only the cocos2d libraries target is selected to avoid any build errors:
Step #5: Build it!
You should now try and build the project. If you’re lucky, there won’t be any errors and you can continue with your work.
But most likely, depending on your project’s complexity and the changes made to cocos2d-iphone, you may have to fix any build errors that occur. Most of them are likely to be caused by classes that have been renamed or functions that have been deprecated. In this case you’ll have to find out through the API Reference and release notes what the changes are and how to fix them.
Fixing the “missing base SDK” message
One common issue that occurs specifically to older projects is the “missing base SDK” error. I think it was the Xcode version introduced with Mac OS X Snow Leopard (released Aug. 28th 2010) that eventually fixed this dreaded issue by adding a “latest iOS” option for the Base SDK Build Setting.
Note: In some cases it may be necessary to close Xcode 4 and re-open it to make the “missing base SDK” message go away.
Correctly Inheriting Build Settings
Normally, all targets in Xcode inherit the Build Settings of the project by default.
However, once you’ve made any change to any Build Setting at the target level this Build Setting will no longer inherit changes made to the same Build Setting on the project level. The default reaction by many developers is often to bite the bullet and check and re-check the Build Settings of the project as well as all targets, and to make the same change as many times as you have targets in your project.
Don’t do that, there’s a better and easier way!
You can have a Build Setting at the target level to default back to inherit the Build Setting defined at the project level. Likewise a Build Setting at the project level can be set to inherit from the OS default setting. In the screenshot below I have purposefully changed the Build Setting at the target level:
Tip: Switching from the Combined to the Levels view when reviewing the Build Settings makes it easy to see which Build Settings are inherited and which aren’t. You’ll also notice that any Build Setting that has been changed at the current level and doesn’t inherit its value anymore is printed in bold letters.
Happy coding with your newly updated cocos2d-iphone project! This upgrade tutorial will also be printed in the second revision of the Learn Cocos2D book.
Tip: With Kobold2D it will be even easier to upgrade your project because a simple copy & paste of the files in the kobold2d folder will suffice. If there are ever any additional steps to follow we’ll describe them in detail of course.
Azam and I thought that the recent news (Zynga hiring Cocos2D key contributors) justifies a Zynga-Special Cocos2D Podcast episode where we talk about Zynga and what this deal might bring for the future.
I have some background with large corporations and was in a startup trying to secure venture capital funding, so I find it specifically interesting to speculate on rationale and things to come.
We now have two almost opposite entities working closely together: Ricardo Quesada, a strong supporter of the open source idea and disapproving commercial exploitation of Cocos2D, and Zynga, one of the fastest growing games company with record revenues and huge venture capital investments going into them. How does this fit together?
Appears to have hand registered the domain names ZyngaCocos.com and ZyngaCocos2D.com
According to WhoIs the domain was registered by MarktMonitor, a company that protects brands and manages domains for large companies, effectively hiding who truly registered the domain. But it’s hard to imagine that anyone but Zynga would register such a domain name.
What does that tell us?
Not much at the moment. People and companies register domains all the time. However, if this domain was indeed registered by Zynga, it at least expresses intent to establish a website or even a brand labelled ZyngaCocos respectively ZyngaCocos2D.
Zynga acquired “certain assets of SapusMedia”, that could mean they also acquired the trademark. If so, that means they could exert control over all ports of Cocos2D – either the developers agree to certain terms in order to continue using the trademark, or they will have to remove all trademarks of Cocos2D and rebrand their engines. Which I don’t think they’ll do because a behavior like that would create lots of negative responses and bad PR.
Given the new domain registration, I believe it is more likely that they simply plan to re-brand Cocos2D (for iPhone) as their own: ZyngaCocos(2D).
I’m sure that some of you will immediately suspect this to become a commercial version of Cocos2D for iPhone but unless they get permission from all contributors, they can’t change the license or would have to remove the code from all contributors who don’t permit them to use their code under a new license. If they do plan to make a commercial version of Cocos2D they would have to essentially rewrite the engine. Or buy out the contributors as well. But it’s not very likely because it would be a difficult process and selling a game engine is not very lucrative – in relation to Zynga’s cash flow of course.
If it is going to be just a simple rebranding of the cocos2d-iphone engine, I’m a bit confused by what they said in the initial announcement after having hired Ricardo and Rolando. They ascertained that the cocos2d-iphone.org website and community will remain independent and administered by Ricardo as he’s done in the past. So that leads me to believe that if there’s a ZyngaCocos2D, it’ll be somehow different and independent from cocos2d-iphone. Unless that was only said to avoid a negative first reaction from the community, and to keep us in the dark.
But I find it hard to imagine that Ricardo would give up his baby only to see it slowly die or let go of it entirely. Now, if you consider Ricardo’s strong connection with cocos2d-iphone and the open source movement and his integrity, I don’t expect a commercial version but one that is open source. And I don’t expect a slowly rotting public version of the cocos2d-iphone engine either, unless ZyngaCocos2D is somehow different from cocos2d-iphone.
I’m really interested now what they’re planning to do. There’s been very little information (in fact: none) revealed about what the future of cocos2d-iphone will look like, and I don’t expect any answers (not even from Ricardo & Rolando) until Zynga make another press release. This leads me to believe there’s only two options:
- Something big will happen, and they want to make sure it’s going to be a big bang announcement. Eg Zynga indeed making a commitment to open source game engine development.
- We won’t like the news, or there really aren’t any, so they’d rather not stir up a fuzz or create false expectations.
I think I’m going with #1 for the time being while expecting the worst. What do you think is going to happen?
I did a little research to figure out more about Zynga’s involvements in open source projects. The research is not comprehensive nor conclusive but provides a little more insight. At least as much as is possible from a corporation with PR departments.
This article reports on Zynga’s involvement as follows:
Casual-game provider Zynga found that its efforts to manage the load of its database operations dovetailed with work being done at NorthScale and NHN and decided to contribute research findings and to the open-source community, as well as sponsoring continuing efforts to maintain and enhance the software.
Sponsoring efforts to maintain and enhance. Sponsoring means there’s money or manpower going into the project. Zynga looks forward to advancing Cocos2D. Notice the difference.
Another article on the same subject quotes Zynga’s CTO Cadir Lee:
“Zynga’s objective was simple: we needed a database that could keep up with the challenging demands of our games while minimizing our average, fully-loaded cost per database operation — including capital equipment, management costs and developer productivity. We evaluated many NoSQL database technologies but all fell short of our stringent requirements. Our membase development efforts dovetailed with work being done at NorthScale and NHN and we’re delighted to contribute our code to the open source community and to sponsor continuing efforts to maintain and enhance the software.”
All except one project on Zynga’s github repository are related to Membase: moxi (forked from membase), zstored, mcmux and pecl-memcached.
In an interview, the Zynga country manager for India Shan Kadavil, refers to Moxi:
Our developers have been involved in various open source projects, including development of open source tools to bug fixes. An example is the Moxi project–when we were looking at scaling our infrastructure, we needed a technology that could help us scale horizontally, add new Web servers as when needed without being bottlenecked at the storage layer. Having examined and scrutinised all the proprietary options, we looked towards open source and found the Moxi project, which worked like a load balancer for the caching layer. We helped scale the Moxi project specifically by adding modifications to handle large cloud computing environments.
This statement did make me wonder what those other open source projects are that Zynga has been involved in? It’s hard to find anything because submitting a code change rarely causes a press release to be issued.
The FontLabel project was released as open source by Zynga. It enables you to render any truetype (ttf) font on the iPhone, not just the built-in fonts provided by Apple. It’s not to be confused with bitmap-font rendering, instead it behaves like UIFont but allows you to use non-system fonts.
FontLabel was added to cocos2d-iphone in September 2009.
To be honest, FontLabel is not the kind of project that would have stopped the world from spinning. But it’s a kind of project that benefits from many developers using, and thus testing it. So making it open source makes sense.
Others OS projects?
It’s hard to find references of Zynga contributing to open source projects, because usually there won’t be a press release issued when a coder submits a fix to a more or less obscure open source project.
I was only aware of one other OS project, that was FontLabel which was actually started by Zynga. If you know an open source project that Zynga contributed to and that I missed, please mention it in a comment, thank you!
But if that is the entire involvement Zynga has with Open Source, then it doesn’t give me the impression that they’re open-source friendly. They support it when it makes sense, for PR, for free beta-testing, or if they need open source technology and want to play nice. In that regard they are no different than any other big company.
Zynga’s view on Open Source
The interview with Zynga’s country manager for India published over a year ago provides some clues.
We think of open source as a movement and not as a particular project. The success of the projects using open source is possible only when multiple people contribute and when the industry endorses them.
Which means that without industry support (read: finances, manpower, marketing) open source projects can not be successful. At least not by their definition of success.
The next statement makes one hopeful:
We have multiple models to involve the community. We have had members from the open source projects work commercially for us to build a platform or tool for us. To that end, we gave the entire output back to the community.
This is practically identical to hiring Ricardo and Rolando. However, I think this statement refers more to contracting agreements rather than employment.
I suspect that Ricardo and Rolando were already working as contractors for Zynga for the past months. From Ricardo’s commits to the cocos2d-iphone project over the past months I always wondered what kind of secret project he was working on. To me the commits looked like by-products of a different, bigger projects. Some commit phases included many smaller changes, not something that you’ll spend your entire day working on.
Before actually moving from continent to continent you almost certainly have to have worked together in some way or another, if only just to get to know each other. So I can imagine something already being developed in secret on a contract basis. The question is, if this is true, what it is and when or if we’ll be seeing it.
The statement following the last one:
Second model is the non-commercial model that involves us getting into open source threads, sharing ideas and work collaboratively with the community with our code fixes.
Ok, so that “model” is basically what any developer does at some point in time. Making code fixes is definitely the easiest way to get something contributed to an open source project, and we all share ideas and collaborate (speak: posting in forums). That sentence made me laugh. Because you can’t really call it a model – it’s what we all do.
How Zynga Germany came to be
By chance I came across another acquisition Zynga made in September 2010. They bought german startup Dextrose (at the time located less than 20 km from where I live) to get ahold of their Aves HTML5 engine and have them become Zynga Germany. Paul Bakaus is co-founder of Dextrose and a jQuery core team member (jQuery UI creator), and now CTO of Zynga Germany.
The interesting aspect here is the Aves engine. It was supposed to be licensed as middleware to other game developers and publishers. But after Zynga’s acquisition it became a proprietary engine and won’t be licensed. All websites of Dextrose and Aves as well as their social networking accounts have since been removed, and Zynga Germany relocated by 80 km to Frankfurt/Main: the city with one of Europe’s busiest airports and many direct flights to overseas. Obviously to make Zynga Germany more accessible for corporate.
Have a look what the engine is capable of and you’ll understand why Zynga had to have it. And why they wanted no one else to have it.
I don’t want to read too much into this, but I’m skeptical. For most corporations, doing good for the community is just not in their program – except of course their PR department. I haven’t found any indication that Zynga is any different. Although they like to be the “google of games”, they’re a far cry from google when it comes to open source projects it seems.
It’s clear that hiring Ricardo and Rolando is providing value for Zynga first and foremost. If it were any other way, the two would not be moving to San Francisco but would be working on a contract basis. Zynga could not possibly buy cocos2d-iphone, so they simply “acquired” the next best thing, which means hiring its key contributors. The cocos2d-iphone project remains untouched, but I worry the emphasis is on remains.
On the other hand, Zynga apparently registered the domain ZyngaCocos2D.com … so maybe there do have bigger plans for cocos2d-iphone?
I assume you’ve heard the news: Zynga hired the cocos2d-iphone lead developer, Ricardo Quesada.
I’d like to try and shed some lights on the open questions that arose. Of course this is my opinion and speculative, so take it with a grain of salt.
What does “acquisition of certain assets of Sapus Media” mean?
Sapus Media products have been bought by Zynga.
These products may be gone for good, or they may be released for free as a concession to the Cocos2D community.
Why did Zynga buy these products?
It’s the cash carrot of the deal. Generally you can expect to receive somewhere around 2 years worth of revenue from a software product as buyout price. Whether Zynga wants or uses the products is irrelevant. It’s the price they paid in order to hire Ricardo and Rolando.
It’s common to bring in new employees by acquiring their legal assets. This keeps the new employees focused on the company’s interests rather than their own, and they no longer have to spend time maintaining and supporting their products. After all, they should focus all their efforts on their new job.
It’s also insurance for the company. By removing in the buy-out what once provided the daily income, the new employees are less likely to leave and more loyal to the company.
Did Zynga also acquire cocos2d-iphone?
I don’t think so.
The cocos2d-iphone engine is a product of Sapus Media. It may be a free and open source project, but legally speaking it has always been an asset of Sapus Media. This means that the copyright of all the cocos2d-iphone.org source code originating from Ricardo or Rolando could have been transferred to Zynga if it was part of the acquisition.
But I think it’s more likely that cocos2d-iphone was merely separated (legally speaking) from SapusMedia, making it an independent project which is owned by those who contributed to it.
The fact that you can still donate to cocos2d-iphone seems to validate this. If cocos2d-iphone were entirely Zynga’s now, I’d expect the donate button to have been removed as well. It would be bad PR for Zynga to take donations from the community for a project that they own.
Why can we still donate to cocos2d-iphone?
Likely to cover running costs.
Zynga did not acquire the cocos2d-iphone.org website and its assets (eg the website design, technology and content). That means donations don’t go to Zynga, and may be used to cover the website’s running costs.
It might also mean that it’s an incentive to keep working on the cocos2d-iphone project, like so many other open source project’s donate buttons.
Whether donations are even necessary, and how much money is needed, we don’t know. Unless there’s more transparency regarding expenses I wouldn’t feel comfortable donating at this point.