0

なぜこれが機能しないのか誰か教えてください。このエラーが発生し続けます:

キャッチされていない例外 'NSInternalInconsistencyException' が原因でアプリを終了しています。理由: 'Layer#ccTouchBegan override me'

取り出したら

[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self 優先度:0 ツバメタッチ:YES];

クラッシュしませんが、機能しません。これは間違いなく答えではありません。

// Import the interfaces
#import "HelloWorldLayer.h"
#import "CCTouchDispatcher.h"

CCSprite *man;
CCSprite *death;

// Needed to obtain the Navigation Controller
#import "AppDelegate.h"

#pragma mark - HelloWorldLayer

// HelloWorldLayer implementation
@implementation HelloWorldLayer


// Helper class method that creates a Scene with the HelloWorldLayer as the only child.
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];

// add layer as a child to scene
[scene addChild: layer];

// return the scene
return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) ) {

    man = [CCSprite spriteWithFile:@"man.png"];
    man.position = ccp(150,150);
    [self addChild: man];
    death = [CCSprite spriteWithFile:@"death.png"];
    death.position = ccp(100,100);
    [self addChild: death];

    [self schedule:@selector(callEveryFrame:)];

    [[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self priority:0    swallowsTouches:YES];

}
return self;
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)

// don't forget to call "super dealloc"
[super dealloc];
}

-(void) callEveryFrame:(ccTime)dt{

man.position = ccp(man.position.x +250*dt, man.position.y);
if (man.position.x > 480 + 64) {
    man.position =ccp(-64,man.position.y);
}
death.position = ccp(death.position.x, death.position.y +100*dt);
if (death.position.y > 300+64){
    death.position =ccp(death.position.x,-64);
   }

}

-(BOOL)CCTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
return YES;
}


 -(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
    CGPoint location = [touch locationInView: [touch view]];
    CGPoint convertedLocation = [[CCDirector sharedDirector]convertToGL:location];

    [man stopAllActions];
    [man runAction:[CCMoveTo actionWithDuration:1 position:convertedLocation]];
}


@end
4

1 に答える 1

0

ccTouchBegan:withEvent:クラスにメソッドを実装していません。

Objective C の変数、クラス、メソッドなどの名前は、大文字と小文字が区別されます。コードを注意深く見てください。

-(BOOL) CC TouchBegan:(UITouch *)touch withEvent:(UIEvent *)イベント{
はいを返します。
}
于 2013-07-19T16:54:54.240 に答える