Archive for the 'cocos2d' Category

Page 2 of 5

Editors

Are you looking for a texture atlas editor ? or for a new TileMapAtlas editor ?
Here are some projects done by the cocos2d community:

Texture Atlas Creator (http://robertjpayne.com/textureatlascreator/)
Features:

  • A simple Texture Atlas editor. Useful if you are going to use AtlasSprites!
  • It lets you import individual images
  • You can place these images withing the atlas
  • You can save the texture atlas image
  • It export the coordinates into an .xml file
  • It’s a web application

Tiled + .tga plugin, a cocos2d TileMapEditor (http://kwigbo.com/wp/2009/03/15/cocos2d-alternative-map-editor/)
Features:

  • It is a plugin of Tiled, a popular tile editor.
  • The plugin supports 3 layers: tile, code and bkgr
  • The plugin supports 2 tilesets: tiles and code
  • It lets you export the map to a .tga file (the format supported by TileMapAtlas)
  • A very good alternative to the PGU level editor

cocos2d v0.7.1 released

Hey,
cocos2d v0.7.1 is available for download.

Download:
http://cocos2d-iphone.googlecode.com/files/cocos2d-iphone-0.7.1.tar.gz

Highlights:

  • Sprite Sheets (For further info please read this post: spritesheet-in-v071 )
  • Local to World coordinates and vice-versa
  • Sound Support (warning: experimental feature)


Compatibility
:
cocos2d v0.7.1 is 90% compatible with v0.7.0. You need to add new files and
you might need to add some linker parameter. Also some selectors were deprecated.
Please, read CAREFULLY the following instructions:

Full Changelog:

  • Actions: added tags to actions (issue #222)
  • Actions: Spawns can be Speeded (issue #257)
  • Actions: Speed can be altered in runtime (part of issue #236)
  • AtlasSprite: Sprite sheet implementation (issue #238)
  • Chipmunk: cpVect is defined as a CGPoint (issue #260)
  • CocosNode: Camera is lazy alloced (issue #94)
  • CocosNode: addChild, removeChild:cleanup, getChildByTag family functions (issue #253)
  • CocosNode: added better comments, cleanup code (issue #219)
  • CocosNode: added RGB protocol: Atlas,Texture & ColorLayer conforms it (issue #234)
  • CocosNode: fixed memory leak when removeAndStop a node with children with actions (issue #254)
  • CocosNode: added transform local to world coordinates that support rotation,scale & position (issue #207)
  • CocosNode: removed scale ivar (issue #231)
  • CocosNode: improved handling of nil parameters (issue #262)
  • CocosLive: filter by device id (issue #223)
  • CocosLive: category is UTF8′ized (issue #227)
  • CocosLive: using cc_playername instead of usr_playername (issue #242)
  • CocosLive: supports “update score” (issue #250)
  • Demos: added performance test (issue #243)
  • Director: FastDirector doesn’t leak autoreleased objects (issue #221)
  • Director: prevents calling startAnimation twice in a row (issue #215)
  • Menu: can be aligned in columns / rows. Updated menu example (issue #206)
  • Menu: MenuItem supports LabelAtlas (issue #235)
  • Menu: MenuItemFont fixed memory leak (issue #232)
  • Menu: MenuItem improved hit testing (issue #214)
  • Scheduler: if signature is not correct Assert (issue #218)
  • Sprite: correct transform anchor point (issue #216)
  • TextureAtlas: support for texture2D (issue #161)
  • Tools: Added perf-test results (issue #243)

As always, big thanks to the community for adding new features, fixing bugs, submitting patches, opening issues, testing the release candidate, etc!!

cpVect vs. CGPoint (Chipmunk vs. CoreGraphics)

Chipmunk has a type called cpVect that is used to define a vector.
The above mentioned structure is defined as:

typedef struct cpVect{ cpFloat x,y;} cpVect;

On the other hand, CoreGraphics has a similar type called CGPoint that is defined as:

struct CGPoint {CGFloat x;CGFloat y;};typedef struct CGPoint CGPoint;

These 2 types has the same attributes (they are identical) but they aren’t interchangeable because they are different types.
You can’t do add a CGPoint with a cpVect, neither you can’t test whether or not a cpVect is inside a CGRect, etc.

Since cocos2d v0.7.1 you will be able to mix them and use them interchangeably. The solution was a simple hack:

// file cpVect.h

#import <CoreGraphics/CGGeometry.h>#define cpVect CGPoint//typedef struct cpVect{// cpFloat x,y;//} cpVect;

Documentation in cocos2d


Perhaps the most important feature that is missing in cocos2d for iPhone is a Programing Guide. In the meantime you can learn cocos2d for iPhone by:

You can also read news and some recipes from these blogs:

And if you have a question and you don’t know who to ask, you can ask it in the cocos2d forum:

Ah… and last but not least, if you are also new to iPhone and objective-c, check this page:

SpriteSheet in v0.7.1

cocos2d v0.7.1 supports SpriteSheets. An SpriteSheet basically is an image that contains subimages, and these subimages can be used as sprites. In cocos2d v0.7.1 these new sprites are called AtlasSprite.

These are the benefits of using AtlasSprite instead of the normal Sprite:

  • Reduces texture memory since all the sprites are in one big image.
  • Reduces render time since there are less OpenGL calls. The new order is O(1) while the order of using normal Sprites is O(n). If you have 400 AtlasSprites, now you have to do 6 OpenGL calls. With 400 Sprites you have to do 400 *6 OpenGL calls.

How do you use it?:

// Create the AtlasSpriteManager
// You can use a .PNG file or a PVRTC image.
// capacity is an optional parameter. It is just a hint that means the quantity of total sprites.
// You can add more (or less) sprites than the quantity.
// grossini_dance_atlas.png is an image than contains the subsprites.
AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"grossini_dance_atlas.png" capacity:50];
 
// You create the sprite
AtlasSprite *sprite = [AtlasSprite spriteWithRect:CGRectMake(x,y,85,121) spriteManager:mgr];
 
// you add the sprite to the parent
// the parent must be the AtlasSpriteManager
// z must be 0.
// You can add tags if you want.
[mgr addChild:sprite z:0 tag:kTagSprite1];
 
// you can transform the sprite
sprite.position = cpv( 200,300 );
sprite.rotation = 90;
sprite.scale = 2.0f;
 
// you can run actions in this new sprite
[sprite runAction: [RotateBy actionWithDuration:2 angle:360]];

The TestAtlas.m file (Example #5) contains a working example of AtlasSprite.
The PerformanceTest example compares Sprite vs AtlasSprite performance (more on this later).

deprecated API in v0.7.1


cocos2d-iphone started as a port of cocos2d-python and during the port most of the function names remained exactly the same. For example, in cocos2d-python to add child to a parent you should do this:

parent.add( child )


and in cocos2d-iphone you should do this:

[parent add:child];

But the name add does not follow the objective-c convention. So, in v0.7.1 these functions will be deprecated. This means that these functions will be still present during the v0.7 series. A warning will be displayed at compile time and at runtime (in debug mode only) but they will still work as expected.
In v0.8 these functions will be removed.

These are the new functions:

Add:

[self add:node];        // OLD[self addChild:node];   // NEW

[self add:node z:0];          // OLD[self addChild:node z:0];     // NEW

[self add:node z:0 tag:t];          // OLD[self addChild:node z:0 tag:t];     // NEW

[self add:node z:0 tag:t parallaxRatio];        // OLD[self addChild:node z:0 tag:t parallaxRatio];   // NEW

Get:

[self getByTag:tag];        // OLD[self getChildByTag:tag];   // NEW

Remove:

[self remove:node];                    // OLD[self removeChild:node cleanup:NO];    // NEW

[self removeAndStop:node];                  // OLD[self removeChild:node cleanup:YES];        // NEW

[self removeByTag:tag];                    // OLD[self removeChildByTag:tag cleanup:NO];    // NEW

[self removeAndStopByTag:tag];              // OLD[self removeChildByTag:tag cleanup:YES];    // NEW

[self removeAll];                           // OLD[self removeAllChildrenWithCleanup: NO];    // NEW

[self removeAndStopAll];                    // OLD[self removeAllChildrenWithCleanup: YES];    // NEW

Actions:

[self do: action];          // OLD[self runAction: action];   // NEW

It is noteworthy the new cleanup parameter. If you want to stop all running actions and/or scheduled functions in a node, use the cleanup parameter with YES.

SpriteSheet in v0.7.1

cocos2d v0.7.1 supports SpriteSheets. An SpriteSheet basically is an image that contains subimages, and these subimages can be used as sprites. In cocos2d v0.7.1 these new sprites are called AtlasSprite.

These are the benefits of using AtlasSprite instead of the normal Sprite:

  • Reduces texture memory since all the sprites are in one big image.
  • Reduces render time since there are less OpenGL calls. The new order is O(1) while the order of using normal Sprites is O(n). If you have 400 AtlasSprites, now you have to do 6 OpenGL calls. With 400 Sprites you have to do 400 *6 OpenGL calls.

How do you use it?:

// Create the AtlasSpriteManager// You can use a .PNG file or a PVRTC image.// capacity is an optional parameter. It is just a hint that means the quantity of total sprites.// You can add more (or less) sprites than the quantity.// grossini_dance_atlas.png is an image than contains the subsprites.AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"grossini_dance_atlas.png" capacity:50];

// You create the spriteAtlasSprite *sprite = [AtlasSprite spriteWithRect:CGRectMake(x,y,85,121) spriteManager:mgr];

// you add the sprite to the parent// the parent must be the AtlasSpriteManager// z must be 0.// You can add tags if you want.[mgr addChild:sprite z:0 tag:kTagSprite1];

// you can transform the spritesprite.position = cpv( 200,300 );sprite.rotation = 90;sprite.scale = 2.0f;

// you can run actions in this new sprite[sprite runAction: [RotateBy actionWithDuration:2 angle:360]];

The TestAtlas.m file (Example #5) contains a working example of AtlasSprite.
The PerformanceTest example compares Sprite vs AtlasSprite performance (more on this later).

deprecated API in v0.7.1


cocos2d-iphone started as a port of cocos2d-python and during the port most of the function names remained exactly the same. For example, in cocos2d-python to add child to a parent you should do this:

parent.add( child )


and in cocos2d-iphone you should do this:

[parent add:child];

But the name add does not follow the objective-c convention. So, in v0.7.1 these functions will be deprecated. This means that these functions will be still present during the v0.7 series. A warning will be displayed at compile time and at runtime (in debug mode only) but they will still work as expected.
In v0.8 these functions will be removed.

These are the new functions:

Add:

[self add:node];        // OLD[self addChild:node];   // NEW

[self add:node z:0];          // OLD[self addChild:node z:0];     // NEW

[self add:node z:0 tag:t];          // OLD[self addChild:node z:0 tag:t];     // NEW

[self add:node z:0 tag:t parallaxRatio];        // OLD[self addChild:node z:0 tag:t parallaxRatio];   // NEW

Get:

[self getByTag:tag];        // OLD[self getChildByTag:tag];   // NEW

Remove:

[self remove:node];                    // OLD[self removeChild:node cleanup:NO];    // NEW

[self removeAndStop:node];                  // OLD[self removeChild:node cleanup:YES];        // NEW

[self removeByTag:tag];                    // OLD[self removeChildByTag:tag cleanup:NO];    // NEW

[self removeAndStopByTag:tag];              // OLD[self removeChildByTag:tag cleanup:YES];    // NEW

[self removeAll];                           // OLD[self removeAllChildrenWithCleanup: NO];    // NEW

[self removeAndStopAll];                    // OLD[self removeAllChildrenWithCleanup: YES];    // NEW

Actions:

[self do: action];          // OLD[self runAction: action];   // NEW

It is noteworthy the new cleanup parameter. If you want to stop all running actions and/or scheduled functions in a node, use the cleanup parameter with YES.

cocos Live v0.1.1 with device id filter


Cocos Live v0.1.1 introduces some changes in the Web front end. The most important change is that now it is possible to the display certain fields in the Web and send back to the iPhone another set of fields.
Use the Sendback property to send a field back to the iPhone and use the Display On Web property to display a field on the web page.
Eg: If you don’t want to send back the usr_playername property to the iPhone, but you want to display it on the web page, then set SendBack = False and Display On Web = True.

In Cocos Live v0.1.1 you can also filter games by device id:

// request scores posted by this device// request scores "all time"// request best 15 scores (limit:15, offset:0)[request requestScores:kQueryAllTime limit:15 offset:0 flags:kQueryFlagsByDevice category:@"easy"];

To filter by device id using the Web front end you need to enable the Display On Web property for the cc_device_id field.
Then, you can click on that field to filter by that device id.

Cocos Live client v0.1.1 will be available with cocos2d v0.7.1, but if you can’t wait, you can download it from the svn rev. 594.

Cocos Live service v0.1.1 is “live” now. To try this feature, you can play filtering the scores of DemoGame game.

cocos2d for iPhone v0.7 released

Download:
http://cocos2d-iphone.googlecode.com/files/cocos2d-iphone-0.7.tar.gz

New features since v0.6.3:

Effects (AKA mesh effects, AKA grid effects):
cocos2d v0.7 let’s you manipulate the CocosNode’s texture like a grid. You can create astonishing effects on your nodes by executing some of the Grid actions.
For further information read this post:
http://blog.sapusmedia.com/2009/02/introduction-to-effects-in-cocos2d.html

Cocos Live (High Score Server):
cocos2d v0.7 comes with an API that let’s you upload your high scores to a free high score server called Cocos Live.
For further information read this post:
http://blog.sapusmedia.com/2009/02/cocos-live-high-score-server-for.html

Improved TileMapAtlas:
cocos2d v0.7 let’s you read/write the TileMapAtlas in runtime.
For further information read this post:
http://blog.sapusmedia.com/2009/02/read-write-tilemapatlas-at-last.html

Improved Alias/Antialias support:
cocos2d v0.7 has a new API to handle your aliased/antialiased textures.
For further information read this post:
http://blog.sapusmedia.com/2009/02/antialiased-aliased-textures-in-cocos2d.html

PVRTC full support:
cocos2d v0.7 supports the “full” PVRTC format, including PVRTC images with mipmap textures.
For further information read this post:
http://blog.sapusmedia.com/2009/02/pvrtc-support-in-cocos2d.html

Fast Director:
cocos2d v0.7 has a new Director, that triggers the main loop every frame. This let’s you gain some FPS in certain conditions.
For further information read this post:
http://blog.sapusmedia.com/2009/02/gaining-some-fps-in-your-game.html

Attach/Detach:
cocos2d v0.7 has a new API that let’s you attach/detach run/restart the director.
For further information please see the AttachDemo example that comes with cocos2d.

How to convert a v0.6.3 project to v0.7.0 ?
Please read this file:
http://cocos2d-iphone.googlecode.com/svn/trunk/tools/convert_0_6_to_0_7.txt

Full Changelog:

  • Action: elapsed is a property (issue #203)
  • Actions: EaseIn/Out added. Cubic/Quad removed (issue #195)
  • Atlas: Fixed black line (issue #135 and issue #47)
  • Atlas: Works when GL_CULL_FACE is enabled (issue #179)
  • Atlas: updateAltasValues renamed to updateAtlasValues (issue #198)
  • CocosLive: added client and example that uses the CocosLive service (issue #175)
  • CocosNode: children is a property (issue #185)
  • CocosNode: rotate before scale (issue #217)
  • Demos: Creating Window and attaching cocos2d to it (issue #180)
  • Demos: Texture2dDemo shows how to load PVR images and PVR Mipmap images (issue #112)
  • Demos: Added AttachDemo (issue #180)
  • Demos: Added EffectsDemo and EffectsAdvancedDemo (issue #183)
  • Director: OpenGLview is attached to a given UIView/UIWindow (issue #180)
  • Director: winSize returns a CGSize (not a CGRect) (issue #159)
  • Director: added FastDirector (issue #145)
  • Director: dispatch missing events in main loop (issue #146)
  • Director: renamed runScene with runWithScene (issue #194)
  • Director: SignificantTimeChange fixed (issue #6)
  • Effects: Added Effects support (Grid and TiledGrid) (issue #183)
  • Effects: Basic: StopGrid, ReuseGrid (issue #183)
  • Effects: Grid: Waves3D, FlipX3D, FlipY3D, Lens3D, Ripple3D, Liquid, Shaky3D, Waves, Twirl (issue #183)
  • Effects: Tiled: ShakyTiles3D, ShatteredTiles3D, ShuffleTiles, FadeOutTRTiles, FadeOutBLTiles, FadeOutUpTiles, FadeOutDownTiles, TurnOffTiles, WavesTiles3D, JumpTiles3D, SplitRows, SplitCols (issue #183)
  • Experimental: Added StreakDemo (issue #171)
  • Menu: aligItemsVerticallyOld removed. (issue #196)
  • MenuItemFont: can be changed in runtime (issue #202)
  • MenuItemFont: assign correct size and documented isEnabled (issue #132)
  • Particle: Buffers updated on update (issue #163)
  • Sprite: initWithPVRTCFile is deprecated. will be removed in v0.8 (issue #197)
  • Texture: Support for full PVRTC (issue #112)
  • Texture: Easier to set Alias and/or AntiAlias texture parameters (issue #135 and issue #47)
  • TileMapAtlas: it is readable / writeable now (issue #200)
  • Transitions: added new Effects transitions: SplitRowsTransition, SplitColsTransition, TurnOffTilesTransition, FadeTRTransition, FadeBLTransition, FadeUpTransition, FadeDownTransition (issue #187)
  • Xcode: treat warnings as errors (issue #201)

Thank you for sending patches, opening issues, fixing bugs, helping people in the forum, sending suggestions, testing the beta and rc versions.

Special thanks to Ernesto Corvi and On-Core for porting all the Effects code from cocos2d-pyhton to cocos2d-iphone!