xcode - Pass Variables to a Function in Objective C -


firstly, let me explain have googled this, , can't seem find clear answer this; believe because using incorrect terminology.

i moving ball location in cocos2d/chipmunk ipad app this:

// determine speed of target         int minduration = 2.0;         int maxduration = 4.0;         int rangeduration = maxduration - minduration;         int actualduration = (arc4random() % rangeduration) + minduration;          nslog([nsstring stringwithformat:@"%d",actualduration]);          // create 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 put piece of code function (perhaps called "method" in obj-c, right?) , pass in name of sprite (in case it's "ball"), x coordinate (location.x) , y coordinate (location.y). ball ccsprite , location's integers.

i beginner @ if provide solution please let me know how clean after (like memory deallocation).

thank much!

here have snippet ok you:

  • (void)moveball:(ccnode*)ball tolocation:(cgpoint)location {

// determine speed of target int minduration = 2.0; int maxduration = 4.0; int rangeduration = maxduration - minduration; int actualduration = (arc4random() % rangeduration) + minduration;

    nslog([nsstring stringwithformat:@"%d",actualduration]);      // create 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];  //-- makes no sense here   } 

you don't need retain ball in function. anyway, since not specify how ball created, assume correctly retained create it. if give more details it, can further.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -