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!