How do I get the center of the screen in cocos2d?

cocos2d-iphone

Solution

Simple, just take the height and width and divide it by 2

CGSize winSize = [[CCDirector sharedDirector] winSize];
CGPoint point = ccp(winSize.width/2, winSize.height/2);

Here is a somewhat more advanced way to do it. This will also work if you have called setPosition on the parent of the sprite (=self in this example)

CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite* centerSprite = [CCSprite spriteWithFile:@"sprite"];
CGPoint centerPoint = ccpSub(ccp(winSize.width/2, winSize.height/2), [self position]);
[centerSprite setPosition:centerPoint];
[self addChild: centerSprite];

Problem

How do I get the world space coordinate of point that is in the center of the screen, in Cocos2d-iPhone?

Original source