Feel free to fix/add documentation to the wiki
cocos2d for iPhone v0.9.0-beta Release Notes
Download
You can download cocos2d for iPhone v0.9.0-beta from here:
http://cocos2d-iphone.googlecode.com/files/cocos2d-iphone-0.9.0-beta.tar.gz
cocos2d v0.9.0-beta is SVN revision 1618
Documentation
You can find the v0.9.0-beta documentation here:
- API Reference: API reference v0.9.0-beta
- Programming Guide: Programming Guide v0.9
Performance
To understand how fast cocos2d v0.9.0-beta is, please see the performance tests:
New features
CC Namespace
Issue #520
v0.9 classes have the CC 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 with
CCbelong to cocos2d. - Classes that don't start with
CCdon't belong to cocos2d
Example:
// v0.8.x classes Sprite *sprite = [Sprite sprite....]; Director *director = [Director sharedDirector]; Scene *scene = [Scene ...]; Layer *layer = [Layer ...]; // 0.9.0 classes CCSprite *sprite = [CCSprite sprite....]; CCDirector *director = [CCDirector sharedDirector]; CCScene *scene = [CCScene ...]; CCLayer *layer = [CCLayer ...];
There are some exceptions:
- The
CocosNodeclass was renamed toCCNode - The
TextureMgrclass was renamed toCCTextureCache
For further info, please see: Migrating to v0.9
Sprite / AtlasSprite merge
Issue #620
In v0.9 AtlasSprite and Sprite were merged in one single class: CCSprite.
New classes:
Sprite→CCSpriteAtlasSprite→CCSpriteAtlasSpriteFrame→CCSpriteFrameSpriteFrame→CCSpriteFrameAnimation→CCAnimationAtlasAnimation→CCAnimationAtlasSpriteManager→CCSpriteSheet← 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 as a fast sprite when it is parented to an CCSpriteSheet.
But CCSpriteSheet has some limitations:
- Only accepts
CCSpritesas children CCSpritesmust have the same texture id as theCCSpriteSheet
CCSpriteFrameCache / Zwoptex support
The animation code in v0.9 was also merged:
- Animation → CCAnimation
- AtlasAnimation → CCAnimation
Migrating 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 is the CCSpriteFrameCache 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 use, you can also add sprite frames to the cache by adding them manually, or by adding them with an NSDictionary.
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] spriteFrameByName:[NSString stringWithFormat:@"grossini_dance_%02d.png",(i+1)]]; [animFrames addObject:frame]; } CCAnimation *animation = [CCAnimation animationWithName:@"dance" delay:0.2f frames:animFrames];
For further info, please see: Migrating to v0.9
CCSpriteSheet supports children
// Create an SpriteSheet CCSpriteSheet *sheet = [CCSpriteSheet spriteSheetWithFile:@"animations/grossini.png" capacity:50]; // Add sprite sheet to parent [self addChild:sheet]; // Load sprite frames [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"animations/grossini.plist"]; CCSprite *sprite1 = [[CCSpriteFrameCache sharedSpriteFrameCache] createSpriteWithFrameName:@"grossini_dance_01.png"]; [sprite1 setPosition:ccp( s.width/3, s.height/2)]; CCSprite *sprite2 = [[CCSpriteFrameCache sharedSpriteFrameCache] createSpriteWithFrameName:@"grossini_dance_02.png"]; [sprite2 setPosition:ccp(50,50)]; CCSprite *sprite3 = [[CCSpriteFrameCache sharedSpriteFrameCache] createSpriteWithFrameName:@"grossini_dance_03.png"]; [sprite3 setPosition:ccp(-50,-50)]; [sheet addChild:sprite1]; // NEW NEW NEW // sprite1 supports children [sprite1 addChild:sprite2]; [sprite1 addChild:sprite3];
Full example:
CCSpriteSheet supports "honor transform" flag
Issue #643
Suppose that you want to create a health bar on top of your sprite. The easiest way to do it is by adding the health bar as a child of your sprite.
This works as expected expect if you sprite rotates, since the health bar will rotate too.
To prevent this behavior the CCSprite object has a new property: honorParentTransform.
By default the child (in our example, the “health bar”) will rotate, translate and scale relative to it's parent. But we can override this behavior by:
// default value healthBar.honorParentTransform = CC_HONOR_PARENT_TRANSFORM_ALL; // ignores parent rotation healthBar.honorParentTransform &= ~CC_HONOR_PARENT_TRANSFORM_ROTATE; // ignores parent scale healthBar.honorParentTransform &= ~CC_HONOR_PARENT_TRANSFORM_SCALE; // ignores parent scale healthBar.honorParentTransform &= ~CC_HONOR_PARENT_TRANSFORM_TRANSLATE;
Full example:
Improved features
Animate
Issue #627
The CCAnimate action now supports reverse.
Example:
id action = [CCAnimate actionWithAnimation: animation restoreOriginalFrame:NO]; id action_back = [action reverse]; [sprite runAction: [CCSequence actions: action, action_back, nil]];
BitmapFontAtlas
Issue #612
CCBitmapFontAtlas works with subdirectories.
Example:
CCBitmapFontAtlas *label1 = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Test" fntFile:@"fonts/bitmapFontTest2.fnt"]; [self addChild:label1];
Box2d
Issue #494
Box2d was updated to r31. Since r31 you should specify body type. Example:
b2BodyDef bd; bd.type = b2DynamicBody; // default type is static body
Chipmunk
Issue #664
- Chipmunk was updated to v5.0.
- The Chipmunk test best was updated to use cocos2d
- The ChipmunkAccelTouch demo was updated to support chipmunk v5.0
ColorLayer
Issue #597
CCColorLayersupports theCCBlendProtocol. You can create “negative” images with it.
Full example:
CocosDenshion
- Added support for detecting ringer/mute switch state
- Doesn't crash when file has no extension
Texture2D
Issue #632
. It's possible to generate mipmap textures in runtime
CCTexture2D *texture0 = [[CCTextureCache sharedTextureCache] addImage:@"grossini_dance_atlas.png"]; // generate mipmap textures [texture0 generateMipmap]; // update the tex parameters so MIPMAP_LINEAR is used ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; [texture0 setTexParameters:&texParams];
Full example:
TextureAtlas
Issue #581
The CCTextureAtlas object (used by CCSpriteSheet) uses by default VBO instead of vertex array list.
TMXTiledMaps
Issue #539
CCTMXTiledMap works with subdirectories.
Example:
CCTMXTiledMap *map = [CCTMXTiledMap tiledMapWithTMXFile:@"TileMaps/orthogonal-test4.tmx"]; [self addChild:map z:0 tag:kTagTileMap];
Transition
Issue #646
- Added
CCCrossFadeTransition. It fades in the incoming scene while the outgoing scene fades out.
Full example:
Compatibility Issues
Please see the Migrating to v0.9 wiki page.
Deprecated /Removed API
Deprecated classes/methods
All deprecated classes/methods in v0.8.x were removed from v0.9
Removed MenuItemAtlasSprite
Issue #620
MenuItemAtlasSprite was removed because:
- In v0.9
CCSpritessupports rects MenuItemAtlasSpritewas a hack. You needed to add the items in 2 different places and it wasn't obvious at all- Usually you don't need a lot of performance to display a menu. If you have 20 items, the performance between
MenuItemAtlasSpriteandMenuItemSpriteshould be more or less equal
Added / Removed Files
Steps to use the v0.9 cocos2d files:
- Open your game XCode project
- From XCode remove the (v0.8) 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
Changes from v0.8.2
Full changelog: CHANGELOG
Changes in v0.9.0-beta
version 0.9.0-beta - 14-Dic-2009
- ActionManager: fixed leak (issue #635)
- Actions: using [self class]. Easier to subclass (issue #655)
- Box2d: updated to r31 (pre 2.1.0) (issue #494)
- Chipmunk: updated to v5.0 (issue #664)
- CocosDenshion: support for detecting ringer/mute switch state (issue #593)
- CocosDenshion: doesn't crash when file has no extension (issue #595)
- ColorLayer: supports Blend Protocol (issue #597)
- Node: vertexZ is translated just once (issue #641)
- Director: call schedulers before glClear in mainLoop (part of issue #533)
- Director: “global” NSBundle to facilitate the integration of more than 1 game (issue #654)
- Particles: code easier to mantain, same performance
- Particles: small performance improvement (issue #661)
- SpriteSheet: supports any level of sub-children (issue #346, issue #665)
- Sprite: supports “honor parent transform” (issue #643)
- Sprite: displayFrame renamed to displayedFrame (issue #XXX)
- Sprite: fixed zwoptex offset & anchorPoint (issue #653)
- Sprite: setDisplayFrame works OK with different texture sizes (issue #666)
- Templates: using SDK 3.0 as base SDK
- Textures: supports mipmap generation (issue #632)
- Texture Atlas: uses VBO instead of vertex array list (issue #581)
- TextureCache: don't use autorelease pool to load images (issue #XXX)
- Tiles: TMX maps supports sub-directories (issue #539)
- Transition: added CrossFadeTransition (issue #646)
Changes in v0.9.0-alpha
version 0.9.0-alpha - 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)
Trace: » logos » start » 0_9_0_beta