Cocos2d v3.0
Cocos2d for iOS (http://www.cocos2d-iphone.org) is one of the most powerful and popular frameworks to develop 2D games with. Its popularity is due to its features: it's open source and 2D; has a wide and collaborative community; supports sprites, collisions, scenes, transitions, audio effects, actions, physics, and animations; and has a lot more features.
At the time of writing this book, the current version is Cocos2d v3.0, released a few months ago, so if you have previous experience with this framework, it is possible that you will find some differences and new features.
Pure Objective-C
The syntax has been improved so method names conform to conventions and the code is now better structured. Also, the C libraries have been removed so now we will use just the Core Foundation classes.
ARC
Previously, the new projects created in Cocos2d didn't use Automatic Reference Counting (ARC) by default, but you could enable ARC with a little refactoring process. Now you can forget all these headaches of retaining, releasing, and autoreleasing memory as v3 is ARC-only.
CCDirector
The former [CCDirector sharedDirector].winSize
feature has been replaced by the new [CCDirector sharedDirector].viewSize
feature.
CCLayer
CCNode
has replaced CCLayer
. Previously, CCLayer
was used mainly to support for touch and accelerometer events but since every node inherits from CCResponder
and has this ability, it's no longer needed. Now CCLayer
can't be inherited to create new classes to represent scenes; instead of this class, you should use CCScene
from now onward.
CCArray
In the first versions of Cocos2d, CCArray
was used thanks to the speed it provided. However, this advantage is no longer the case and during Cocos2d v2, a lot of developers were recommending not to use this class to manage arrays. That's why it has been deprecated in this new version and is no longer available.
OALSimpleAudio
CocosDenshion's SimpleAudioEngine
, an external class, previously supported sound and audio effects. From now, ObjectAL's OALSimpleAudio
class has replaced SimpleAudioEngine
. This new class is focused on doing what we need in a simple way, converting complex actions into easy tasks.
CCAction
Almost all the action classes have been renamed to something like CCActionNameAction
; despite this, its syntax remains unaltered.
CCActionCallBlock
Good-bye CCCallBlock
, hello CCActionCallBlock
. Something similar to what happened to CCAction
also happens to CCCallBlock
; it has been renamed but its syntax remains unaltered.
Sequences
The former CCSequence
class is now named CCActionSequence
and the most important change in this case is that when passing the array of actions to the sequences, you don't have to pass a nil object as the last element.
Schedule update
In the previous version, you should execute scheduleUpdate
in order to schedule the update method to be called every frame. This is not needed anymore; now you just need to implement the update
method in the way you want to work.
Enabling touches
Touch handling is now performed by CCNode
and therefore by its descendants. To enable it now, you will need to set userInteractionEnabled
to TRUE
and implement either touchBegan
, touchMoved
, touchEnded
, or touchCancelled
.
Accelerometer events
As with touches, to enable accelerometer events handling, you need to set userInteractionEnabled
to TRUE
and you will also need to add the Core Motion framework.
Physics
Unlike what happened in Cocos2d v2, physics are now based on Chipmunk. Previously, we had both Box2D and Chipmunk to implement physics, but now the only library will be Chipmunk.