0.9 new features.
Focus on the following.
1. All namespaces start with CC (abnormal)
2. If you are used to spritemananger, you have to use ccspritesheet.
3. atlassprite and sprite are integrated, that is, ccsprite.
Version 0.9.0-18-nov-2009
. ALL: using CC namespace (Issue #520)
. ALL: prevents warnings with static analizer (Issue #613)
. ALL: Cocos protocols renamed to avoid confusion (part of Issue #520)
. ALL: added compatibility with v0.8 (part of Issue #520)
. Animation: supports duration and reverse (Issue #627)
. Tests: performance tests re-integrated to main xcode Project (Issue # XXX)
. Bitmapfontatlas: Works with subdirectories (Issue #612)
. Box2d: Updated to R26 (pre 2.1.0) (Issue #494)
. Cocoslive: Uses Cl namespace (part of Issue #520)
. Cocoslive: Uses ASCII encoder (Issue #617)
. Sprite: Sprite and atlassprite merged in just one class (Issue #620)
. Sprite: atlasspritemanager renamed to spritesheet (Issue #620)
. Sprite: SPRITE frames and animations supports flipx/flipy (Issue #620)
. Spriteframecache: added an easier way to create animations and Sprites (Issue #620)
. Templates: Updated (part of Issue #520 and issue #620)
. Templates: Includes cocos2d and cocosdenshion licences files
. Texturemgr: renamed to texturecache (part of Issue #620)
. Xcode: textures files in 1 xcode group (texture2d, pvrtexture, texturealtas, texturecache)
Installing v0.9
Once you have tested that your game runs without warnings using v0.8.2, you can replace cocos2d v0.8.2 with cocos2d v0.9.0.
Steps to replace it:
- Open your game xcode Project
- From xcode remove the cocos2d Folder: delete the references also moving them to the trash folder
- Download cocos2d v0.9 (latest v0.9 Version)
- Copy the v0.9 cocos2d directory to your game directory
- From xcode, include the recently copied cocos2d directory
Enabling compatibility
Once you have installed cocos2d v0.9, you should enable compatibility with v0.8.
Steps to enable compatibility:
- Edit the file
Cocos2d/ccconfig. h
- Uncomment the line:
# Define cc_compatibility_with_0_8 1
// The following line shocould be uncommented# Define cc_compatibility_with_0_8 1
IfCompatiblity ModeIs enabled, then for each new v0.9 class, an old v0.8 class will be added as a subclass of the new one.
Eg:
// If v0.8 compatiblity mode is enabled, then this code will be added_ Attribute __((Deprecated))@ InterfaceSprite:Ccsprite@ End_ Attribute __((Deprecated))@ InterfaceDirector:Ccdirector@ End // Etc... Etc ..
Important: It is recommended to disable compatibility with v0.8 once your project compiles OK with v0.9.
Updating your code
Once compatibility is enabled, You can compile your project. You will find several warnings and errors, but don't panic.
Adding namespaces
V0.9 classes haveCC
Prefix. This prefix was added in order to prevent collision with other possible libraries or user code. So, it is safe to assume that:
- Classes that start
CC
Belong to cocos2d.
- Classes that don't start
CC
Don't belong to cocos2d
Example:
// V0.8.x classes Sprite * Sprite = [ Sprite .... ] ; Director * Director = [ Director shareddire ] ; Scene * Scene = [ Scene... ] ; Layer * Layer = [ Layer... ] ; // 0.9.0 classes Ccsprite * Sprite = [ Ccsprite Sprite .... ] ; Ccdirector* Director = [ Ccdirector shareddire ] ; Ccscene * Scene = [ Ccscene... ] ; Cclayer * Layer = [ Cclayer... ] ;
There are someExceptions:
- The
Cocosnode
Class was renamedCcnode
- The
Texturemgr
Class was renamedCctexturecache
Updating sprites
In v0.9Atlassprite
AndSprite
Were merged in one single class:Ccsprite
.
New classes:
Sprite
→Ccsprite
Atlassprite
→Ccsprite
Atlasspriteframe
→Ccspriteframe
Spriteframe
→Ccspriteframe
Animation
→Ccanimation
Atlasanimation
→Ccanimation
Atlasspritemanager
→Ccspritesheet
Creating new name
Example:
// V0.8 code: Atlas sprites Atlasspritemanager * Mgr = [ Atlasspritemanager spritemanager... ] ; Atlassprite* Sprite = [ Mgr createspritewith... ] ; [ Mgr addchild : Sprite ] ; // V0.9 code Ccspritesheet * Sheet = [ Ccspritesheet spritesheet... ] ; Ccsprite * Sprite = [ Sheet createspritewith... ] ;[ Sheet addchild : Sprite ] ; // V0.8 code: sprites Sprite * Sprite = [ Sprite spritewith... ] ; [ Self addchild : Sprite ] ; // V0.9 code Ccsprite * Sprite = [ Ccsprite spritewith... ] ; [ Self addchild : Sprite ] ;
As you can see,Ccsprite
Can be used as a normal sprite or asFastSprite when it is parented toCcspritesheet
.
For the moment,Ccspritesheet
Has the same limitationsAtlasspritemanager
. LimitationsCcspritesheet
:
- Only accepts
Ccsprites
As children
Ccsprites
Must have the same texture ID asCcspritesheet
Ccsprites
Can't contain children. Only 1 level of children is supported
Updating animationmigrating animation to ccanimation
V0.8 code:
Animation*Sapusanim= [Animation animationwithname:@"Select"Delay:0.3f Images:
@"Sapusselected1.png",
@"Sapusselected2.png",@"Sapusselected1.png",@"Sapusunselected.png",Nil];
V0.9 code:
Ccanimation * Sapusanim = [ Ccanimation animationwithname : @ "Select" Delay : 0.3f ] ; [ Sapusanim addframewithfilename : @ "Sapusselected1.png" ] ; [ Sapusanim addframewithfilename : @ "Sapusselected2.png" ] ; [ Sapusanim addframewithfilename : @ "Sapusselected1.png" ] ; [ Sapusanim addframewithfilename : @ "Sapusunselected.png" ] ;
Migrating atlasanimation to ccanimation
V0.8 code:
Atlasanimation * Animfly = [ Atlasanimation animationwithname : @ "Fly" Delay : 0.2f ] ; [ Animfly addframewithrect : Cgrectmake ( 64 * 0, 64 * 0, 64 , 64 ) ] ; [ Animfly addframewithrect : Cgrectmake ( 64 * 1 , 64 * 0, 64 , 64 ) ] ; [ Animfly addframewithrect : Cgrectmake ( 64 * 2 , 64 * 0, 64 , 64 ) ] ;
V0.9 code:
Ccanimation * Animfly= [ Ccanimation animationwithname : @ "Fly" Delay : 0.2f ] ; [ Animfly addframewithtexture : Spritesheet. Texture rect : Cgrectmake ( 64 * 0, 64 * 0, 64 , 64 ) ] ; [ Animfly addframewithtexture : Spritesheet. Texture rect : Cgrectmake ( 64 * 1 , 64 * 0, 64 , 64 ) ] ; [ Animfly addframewithtexture : Spritesheet. Texture rect : Cgrectmake( 64 * 2 , 64 * 0, 64 , 64 ) ] ;
Taking advantage of ccspriteframecache
One of the benefits of v0.9 isCcspriteframecache
Class, since it lets you write animation code more easily.
Ccspriteframecache
Is an sprite frame cache. Basically you can add frames to this cache, and you can get them by name. You can easily create an animation using the frame cache.
Ccspriteframecache
Supports the zwoptex format. the zwoptex format is easy to parse and use. in case you decide not to use, you can also add sprite frames to the cache by adding them manually, or by adding them withNsdictionary
.
Eg:
// Loads the sprite frames from a zwoptex generated file[[Ccspriteframecache sharedspriteframecache]Addspriteframeswithfile:
@ " animations/grossini. plist " ] ; nsmutablearray * animframes = [ nsmutablearray array ] ; for ( int I = 0; I 14 ; I ++ ) { ccspriteframe * frame = [ [ ccspriteframecache sharedspriteframecache ] S
Priteframebyname:[NsstringStringwithformat:@"Grossini_dance_10902d.png",(I+1)]];[Animframes addobject:Frame];}Ccanimation*Animation= [Ccanimation animationwithname:@"Dance"Delay:0.2f Frames:Animframes];
Tips
Add your own experience here
Recommendations based on the experience migrating games to v0.9:
- Automatically replace:
[Director
To[Ccdirector
- Automatically replace:
Texturemgr
ToCctexturecache
- Automatically replace:
Sharedtexturemgr
ToSharedtexturecache
- Be careful when replacing sprites.
Here's my blog entry about refreshing the transition: http://paulhart.ca /? P = 12
I had to replace
Sprite * s = [atlassprite spritwithrect :... Spritemanager: Mgr]
With
Ccsprite S = [Mgr createspritewithrect:…]
I found this useful when loading images I. e. uiimage into a ccanimation
Ccanimation*An= [Ccanimation animationwithname:@"Myoverlayanimation"Delay:0.5];
//: Dbolli: 091129 11:08:00 init animation with no textures
//: Dbolli: 091205 11:15:50 removed Param 3 textures: nil for cocos2d 9.xUiimage*Myoverlayimage= [Uiimage imagewithcontentsoffile:
[[NsbundleMainbundle]Pathforresource:@"My overlay.png"Oftype:Nil]];//: Dbolli: 091205 11:18:57 note: this image is an example placeholder for
Uiimage created on the fly within the app. addframewithfilename: above is
Easiest way to simply load an image... [An addframewithtexture:[[Cctexture2d alloc]Initwithimage:Myoverlayimage
Switch from cocos2d without translation