How do I get the world space coordinate of point that is in the center of the screen, in Cocos2d-iPhone?
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With