2011-06-30 97 views
0

我試圖使我第一次cocos2d的,花栗鼠iPad應用iPad應用程序與NSInvalidArgumentException

我在.h文件中這樣設置一個「球」精靈崩潰:

// HelloWorld Layer 
@interface 
HelloWorld : CCLayer {  
    cpSpace *space; 
    CCSprite *ball;  
} 

,我感動像這樣(在觸摸):

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    for(UITouch *touch in touches) { 
     CGPoint location = [touch locationInView: [touch view]]; 

     location = [[CCDirector sharedDirector] convertToGL: location];   

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

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

     [ball retain]; 
    } 
} 

當我與調試器中運行,我得到這樣的:

2011-06-29 20:44:04.121 ballgame[3499:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HelloWorld spriteMoveFinished:]: unrecognized selector sent to instance 0x605a3e0' 

它似乎適用於情侶接觸,然後它似乎崩潰,所以也許它的內存泄漏?任何建議或建議真的會有所幫助,這就像我的第一個應用程序。

乾杯!

回答

4

您正在調用不存在的HelloWorld對象上的方法(spriteMoveFinished:)。你做了一個spriteMoveFinished:方法嗎?

'無法識別的選擇器發送'=調用不存在的方法。

2

您是否嘗試調試您的應用程序?也可以根據你的崩潰日誌嘗試NSZombie,其中一個對象被釋放,並且你調用了一個函數。在您的環境標誌中嘗試使用NSZombieEnable。

2

您是否定義了spriteMoveFinished:方法?如果沒有,請定義它。如果已經存在,那麼你的HelloWorld對象可能沒有被保留在任何地方。