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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:13:05+00:00 2026-05-23T11:13:05+00:00

Firstly, let me explain that I have googled this, and I can’t seem to

  • 0

Firstly, let me explain that I have googled this, and I can’t seem to find a clear answer to this; but I believe this is because I am using incorrect terminology.

I am moving a ball to a location in a cocos2d/chipmunk ipad app like this:

// Determine speed of the target
        int minDuration = 2.0;
        int maxDuration = 4.0;
        int rangeDuration = maxDuration - minDuration;
        int actualDuration = (arc4random() % rangeDuration) + minDuration;

        NSLog([NSString stringWithFormat:@"%d",actualDuration]);

        // Create the actions
        id actionMove = [CCMoveTo actionWithDuration:0.2 
                                            position:ccp(location.x, location.y)];
        id actionMoveDone = [CCCallFuncN actionWithTarget:self 
                                                 selector:@selector(spriteMoveFinished:)];
        [ball runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];

        [ball retain]; 

I want to put this piece of code into a function (perhaps called a “method” in Obj-C, right?) and pass in the name of the sprite (in this case it’s “ball”), the x coordinate (location.x) and the y coordinate (location.y). The ball is a CCSprite and the location’s are integers.

I am a beginner at this so if you provide a solution please let me know how to clean up after it (like memory deallocation).

Thank you so much!

  • 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-23T11:13:06+00:00Added an answer on May 23, 2026 at 11:13 am

    Here you have a snippet that could be ok for you:

    • (void)moveBall:(CCNode*)ball toLocation:(CGPoint)location {

    // Determine speed of the target
    int minDuration = 2.0;
    int maxDuration = 4.0;
    int rangeDuration = maxDuration – minDuration;
    int actualDuration = (arc4random() % rangeDuration) + minDuration;

        NSLog([NSString stringWithFormat:@"%d",actualDuration]);
    
        // Create the actions
        id actionMove = [CCMoveTo actionWithDuration:0.2 
                                            position:ccp(location.x, location.y)];
        id actionMoveDone = [CCCallFuncN actionWithTarget:self 
                                                 selector:@selector(spriteMoveFinished:)];
        [ball runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
    
        //        [ball retain];  //-- this makes no sense here
    
     }
    

    You don’t need to retain ball in this function. Anyway, since you do not specify how ball is created, I assume that it is already correctly retained where you create it. If you give more details about it, I can help further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, let me say that I've been on this issue for pretty much 2
Firstly, what i am trying to do is have a page that users can
Firstly, let me just state for the record that this is in prep for
Firstly, let me explain what I'm building: I have a D3.js Force Layout graph
Firstly, let me start by saying that I haven't ever directly used SQL views.
Firstly, let me say that I've been searching the Internet, rewriting scripts and I
Firstly, I know this [type of] question is frequently asked, so let me preface
Well, the question is not intended to be that big. Let me explain the
Let's say I have some email: some_email@yahoo.com . Firstly I would want to remove
Hope you can help me with this: So, I have Nivo slider working fine

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.