2011-06-30 21 views
0

私は私の最初のcocos2dを作成しようとしています私はこのような私の.hファイルに「ボール」スプライトを設定 iPadアプリはNSInvalidArgumentException

、シマリスiPadアプリでクラッシュ:

// 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を試してみてください。あなたのオブジェクトの1つが解放され、その上で関数を呼び出しました。あなたの環境フラグでNSZombieEnableを試してください。

2

spriteMoveFinished:メソッドを定義しましたか?そうでない場合は、定義します。すでに存在する場合、HelloWorldオブジェクトはおそらくどこにも保持されていません。