- Read two amazingly clear tutorials, which may help every Cocos beginner: How to make a simple iPhone game with Cocos2D and Intro to Box2D with Cocos2D Tutorial: Bouncing Balls. Also check others tutorials from him.
- PVR – PowerVR graphic file – smaller than PNG and others, but have to be squared and sized as power of two.
- Objective-C: You can’t remove an object from an array while you are iterating through it.
- Will use FSM for enemies in my yet-to-be-announced game.
- XML parsers for iPhone.
- Efficient random for iPhone (source):
int number = (arc4random() % max) + min;
A* Search algorithm
A* search algorithm used for path finding and even checking tiles on tiled maps (example: Puyo game from iPhone Games Projects bonus chapter: http://apress.com/book/downloadfile/4448 – it uses A* to iterate through the blocks checking for 4 of the same color).
- Each grid block is a node.
- Nodes that have been examined when looking for a path: closed list.
- Nodes yet to be examined: open list.
- Starting node to goal node: moves list.
- Example A* Cocos2D and objective-C code (haven’t tested it tho): http://www.cocos2d-iphone.org/forum/topic/6828#post-41478
- Transform anchor: coordinates used by Cocos to rotate objects on screen. For sprites, the default is the middle of the image.
- ccp(x, y) is Cocos shortcut macro to CGPointMake.
- Scene: a container of all the stuff you’re going to show on screen in a specific part of your game: Main menu, level, help, highscores (each one is a different scene).
- Hierarchy: Scene : Layer : Node : Node.
- A node can be a sprite, label, etc. Note that a sprite may have a child sprite.
- Add nodes to a layer with addChild method.
- Scenes have depth ordering (z): lower Z objects appear behind higher Z ones (er, ok, very old thing, we learn this when we are 8? but always worth noting :) ).
- Cocos auto dealloc all children.
- Run an action:
[node (sprite, etc) runAction:[CCSequence (or CCSpawn) actions:action1, action2, CCCallFunN (callback on the object when the actions are performed)]].
- How to load a sprite:
CCSprite *sprite = [CCSprite spriteWithFile:@"image.png" rect:CGRectMake(0, 0, w, h)]; sprite.position = ccp(x, y);
- UIKit: 0,0 from top left.
- Cocos2d: 0,0 from bottom left.
- Sprites: 0,0 from bottom left.
- Box units are in “meters” ranging from 0.1 to 10. Use macro: PTM_RATIO 32.0 to convert pixels to meters, example:
- World object: manages all the objects and the physics simulation.
- Bodies: movable and static.
- Definition (b2BodyDef): The body definition holds the data needed to create and initialize a body – position, velocity, type.
- Object (b2Body): “body factory”: myWorld->CreateBody(&bodyDef);
- Shape (b2PolygonShape, b2CircleShape, etc): geometry you wish to simulate.
- Fixture definition (b2FixtureDef): binds a shape to a bodys. Shapes don’t know about bodies, that’s why we need fixtures. Defines:
4.1) Density (more dense, more mass = harder to move).
4.2) Friction (0…1 – how hard for objects to slide against each other).
4.3) Restitution (how “bouncy” is an object. 0 = no bounce, 1 = perfectly elastic).
- Fixture object (b2Fixture): b2Fixture* myFixture = myBody->CreateFixture(&fixtureDef);. A body may have any number of fixtures.
Cocos2d Image credits: Official wiki