私は現在、ユーザーのタッチ位置を検出しようとしているアプリケーションを実行しています。
「タッチ位置検出」機能を実装する過程で、ccTouchBegan から ccTouchesBegan に変更しました。
しかし、私はそれを機能させることができません。ccTouchBegan から ccTouchesBegan に変更しました。
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
使用する代わりに:
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
これを行うと、画面をクリックすると全体がクラッシュします。SIGABRT エラーの強調表示の生成:
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
NSAssert(NO, @"Layer#ccTouchBegan override me");
return YES;
}
#endif
@end
だから私の質問は:
なぜクラッシュすると思いますか?
ccTouchBegan と ccTouchesBegan の違いは何ですか? マルチタッチ機能?
さらにヘルプが必要な場合は、これが私のコードです:
-(id) init
{
if( (self=[super init])) {
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
self.isTouchEnabled = YES;
// Set up background
background = [CCSprite spriteWithFile:@"Image.png"];
background.scaleX = 1;
background.scaleY = 1;
background.position = ccp(0,0);
[self addChild:background];
[[CCTouchDispatcher sharedDispatcher]addTargetedDelegate:self
priority:0
swallowsTouches:YES];
// Preload sound effect
soundFile = [SimpleAudioEngine sharedEngine];
if (soundFile != nil) {
[soundFile preloadBackgroundMusic:@"sound.wav"];
}
}
return self;
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
NSLog(@"ccTouchesBegan");
// Sets the sound variable to YES
ifOne = YES;
prevPos = [touch locationInView:[touch self]];
prevPos = [[CCDirector sharedDirector] convertToGL:[touch locationInView:touch.self]];
[self schedule:@selector(timerUpdate:) interval:0.1];
//return YES;
}