如何在Cocos2d-iPhone中获得位于屏幕中心的点的世界空间坐标?
简单,只需取高度和宽度,然后除以2即可
- CGSize winSize = [[CCDirector sharedDirector] winSize];
- CGPoint point = ccp(winSize.width/2,winSize.height/2);
这是一种更先进的方法.
如果您在精灵的父级上调用了setPosition(在此示例中为self),这也可以工作
- 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];