Cocos2d 0.9 new features porting from 0.82 to 0.9

Source: Internet
Author: User

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 fileCocos2d/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 haveCCPrefix. 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 startCCBelong to cocos2d.
    • Classes that don't startCCDon'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:

    • TheCocosnodeClass was renamedCcnode
    • TheTexturemgrClass was renamedCctexturecache
Updating sprites

In v0.9AtlasspriteAndSpriteWere merged in one single class:Ccsprite.

New classes:

    • SpriteCcsprite
    • AtlasspriteCcsprite
    • AtlasspriteframeCcspriteframe
    • SpriteframeCcspriteframe
    • AnimationCcanimation
    • AtlasanimationCcanimation
    • AtlasspritemanagerCcspritesheet 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,CcspriteCan be used as a normal sprite or asFastSprite when it is parented toCcspritesheet.

For the moment,CcspritesheetHas the same limitationsAtlasspritemanager. LimitationsCcspritesheet:

    • Only acceptsCcspritesAs children
    • CcspritesMust have the same texture ID asCcspritesheet
    • CcspritesCan'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 isCcspriteframecacheClass, since it lets you write animation code more easily.

CcspriteframecacheIs 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.

CcspriteframecacheSupports 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:[DirectorTo[Ccdirector
    • Automatically replace:TexturemgrToCctexturecache
    • Automatically replace:SharedtexturemgrToSharedtexturecache
    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.