【发布时间】:2011-06-30 17:50:47
【问题描述】:
首先,让我解释一下,我已经用谷歌搜索过,但我似乎无法找到明确的答案;但我相信这是因为我使用了不正确的术语。
我正在将球移动到 cocos2d/chipmunk ipad 应用程序中的某个位置,如下所示:
// 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];
我想将这段代码放入一个函数中(在 Obj-C 中可能称为“方法”,对吧?)并传入精灵的名称(在本例中为“球”),x 坐标(location.x) 和 y 坐标 (location.y)。球是 CCSprite,位置是整数。
我是这方面的初学者,所以如果您提供解决方案,请告诉我如何清理它(如内存释放)。
非常感谢!
【问题讨论】:
-
Objective-C 有功能;尽管它们是相关的,但它们与方法不同。方法是属于对象的某种函数。语法略有不同 -- 方法:
- (void) thisIsAMethodWithAParameter: (int)param { return; }功能:void thisIsAFunction(int param){ return; } -
感谢乔希的澄清
标签: objective-c xcode ipad cocos2d-iphone chipmunk