This is one my first ventures into the world of iOS development. I am trying to make a simple app where a big ball pushes around a little ball. I have been reading a couple tutorials and I am stuck at the very first point. Please let me know if I’m doing anything crazy (which I probably am). Any suggestions at all will be hugely appreciated. The following code is located in my init function:
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite *player = [CCSprite spriteWithFile:@"player.png"
rect:CGRectMake(0, 0, 40, 40)];
player.position = ccp(player.contentSize.width/2 + 10, winSize.height/2);
[self addChild:player];
CCSprite *ball = [CCSprite spriteWithFile:@"ball.png"
rect:CGRectMake(0, 0, 20, 20)];
ball.position = ccp((player.contentSize.width/2 + 10)+ball.contentSize.width/2, winSize.height/2);
[self addChild:ball];
The player is the bigger ball of course. I would guess that this code should put both balls in the vertical center of the screen. But what I get is this:

Why is the second ball’s center lower than the bigger ball’s center? It was my understanding that you should consider the dead center of the sprite to be the point at which you position the sprite and that winSize.height / 2 should put both sprites in the vertical middle. I am defining the sizes (I think) as 40×40 and 20×20, I made sure that these images are exactly this size.
If you see anything on an unrelated note about my code, please suggest a better / more efficient way of doing things.
Thanks!
The position is referenced to the upper left-hand corner. If you change your code to this, both should be centered (notice subtracting half of the height). You may need to change the size for the rect to match the actual size of the .png’s if they aren’t the same.