Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6068451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:42:58+00:00 2026-05-23T09:42:58+00:00

This is one my first ventures into the world of iOS development. I am

  • 0

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:

enter image description here

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:42:58+00:00Added an answer on May 23, 2026 at 9:42 am

    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.

    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 - player.contentSize.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 - ball.contentSize.height/2);
    [self addChild:ball];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For one of my first ventures into JQuery, I have the very simple goal
This one is a huge issue: first off, while I know a little bit
I can't figure this one out. At first let me say that my cache
I have two arrays the first one has this structure Parameter Keys array array
Racking my brains on this one. I have the code below: the first stages
First of all I did gave a look at this one. But I didn't
I'm following a bioinformatics text, and this represents one of my first Perl scripts.
So this was one of my very first questions here, but I have a
This is my second question on Bamboo ( My First One ). My understanding
This is kinda....a two part question. The first one is much more important than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.