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 8337625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:21:19+00:00 2026-06-09T04:21:19+00:00

When the user taps a button, I want to move a sprite to the

  • 0

When the user taps a button, I want to move a sprite to the next nearest ball (sprite), so they can move from place to place.

As there will only be a limited amount of balls on the screen at a time, I was thinking I should store them in an array, and then when they move offscreen (are destroyed by a function I have in place), they are removed from the array.

I have the current setup (not in a loop atm) :

ball = [[CCSprite spriteWithFile:@"ball.png"] retain];
ball.position = ccp(randX, randY);

NSMutableArray *myArray = [[NSMutableArray alloc] init];  
[myArray addObject: ball];
[myArray addObject: ball];
[myArray addObject: ball];

for (int i = 0; i < 2; i++) {
    CCSprite *sprite = [myArray objectAtIndex:i];
    NSLog(@"%@", sprite.position.x);
}

Why is NSLog printing “(null)” to the console?

  • 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-06-09T04:21:21+00:00Added an answer on June 9, 2026 at 4:21 am

    It looks like you actually want to find the sprite with the lowest X position:

    CCSprite *sprite = [myArray objectAtIndex:0];
    
    for (CCSrpite *s in myArray)
    {
        if (s.position.x < sprite.position.x)
            sprite = s;
    }
    
    // now 'sprite' will contain the sprite with the lowest X position
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show different image for button after user taps that button ...
I have a UITextView and I want have two buttons. When the user taps
Suppose user taps on a button and video begins to play. Now when video
I'm having some trouble dynamically removing UITextFields from my scrollview when the user taps
I want to develop an app for WP7 using C# where a user taps
I have an action which begins when the user taps a button on the
I have my main view, and when a user taps a 'Show' button I
When user taps on a button, I am displaying a whole new view (administration
I have a view basic UITextField and submit button. When the user taps in
Scenario: User taps a button asking for some kind of modification on address book.

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.