私はアプリを作成していますが、画面上にスプライト(2番目のスプライトを上にドラッグ)をドラッグできるようにしようとしていますが、スプライト他のメソッドが呼び出されるはずです。タップとドラッグを区別する方法
私はスプライトの端に触れるとドラッグがうまく動作しますが、スプライトの中央からドラッグしようとすると(2番目のスプライトが上にあります)、ドラッグはまったく機能しませんがタップが呼び出されます。
私はなぜこれをやっていないのか知っています。トップにあるものは、それの下の2番目のものに当たる前にタッチを飲み込んでいるので、両方のスプライトから相反する接触があります。
指を動かすとスプライトをドラッグしたいが、タップが与えられたときにタップを登録したい(IEは画面上を移動しなかった)のはどうだろうか?
私が働いているスプライトの視覚的な(それは場合に役立ちます):(関与アニメーションがありますので)黄色ルーン石からその下に別のスプライトである
。
--------Touch for the top sprite----------
-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event{
lastTouchLocation = [RuneScene locationFromTouch:touch];
BOOL isTouchHandled = CGRectContainsPoint([charSprite boundingBox], lastTouchLocation);
return isTouchHandled;
}
-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event{
NSLog(@"Tap received!");
}
------Touch for the bottom sprite--------
-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event{
lastTouchLocation = [RuneScene locationFromTouch:touch];
BOOL isTouchHandled = NO;
// Check if this touch is on the Spider's sprite.
if (CGRectContainsPoint([current.runeSprite boundingBox], lastTouchLocation)){
mover = current;
isTouchHandled = YES;
}
else if(CGRectContainsPoint([rune1.runeSprite boundingBox], lastTouchLocation)){
mover = rune1;
isTouchHandled = YES;
}
else if(CGRectContainsPoint([rune2.runeSprite boundingBox], lastTouchLocation)){
mover = rune2;
isTouchHandled = YES;
}else if(CGRectContainsPoint([rune3.runeSprite boundingBox], lastTouchLocation)){
mover = rune3;
isTouchHandled = YES;
}else if(CGRectContainsPoint([rune4.runeSprite boundingBox], lastTouchLocation)){
mover = rune4;
isTouchHandled = YES;
}else if(CGRectContainsPoint([rune5.runeSprite boundingBox], lastTouchLocation)){
mover = rune5;
isTouchHandled = YES;
}else if(CGRectContainsPoint([rune6.runeSprite boundingBox], lastTouchLocation)){
mover = rune6;
isTouchHandled = YES;
}else if(CGRectContainsPoint([rune7.runeSprite boundingBox], lastTouchLocation)){
mover = rune7;
isTouchHandled = YES;
}else if(CGRectContainsPoint([rune0.runeSprite boundingBox], lastTouchLocation)){
mover = rune0;
isTouchHandled = YES;
}
// Stop the move action so it doesn't interfere with the user's scrolling.
//[self stopActionByTag:ActionTagCastingLayerMovesBack];
// Always swallow touches, GameLayer is the last layer to receive touches.
return isTouchHandled;
}
-(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event{
CGPoint currentTouchLocation = [RuneScene locationFromTouch:touch];
// Take the difference of the current to the last touch location.
CGPoint moveTo = ccpSub(lastTouchLocation, currentTouchLocation);
// Then reverse it since the goal is not to give the impression of moving the camera over the background,
// but to touch and move the background.
moveTo = ccpMult(moveTo, -1);
lastTouchLocation = currentTouchLocation;
[self moveActionWithLocation: moveTo];
}
-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event{
if (!current.isPlaced && mover == current && currentR < Rune6) {
// Move the game layer back to its designated position.
CCMoveTo* move = [CCMoveTo actionWithDuration:1 position:curPt];
CCEaseIn* ease = [CCEaseIn actionWithAction:move rate:0.5f];
//ease.tag = ActionTagCastingLayerMovesBack;
[current.runeSprite runAction:ease];
[current setIsPlaced:YES];
current.charSprite = [characters objectAtIndex:currentR];
current.charSprite.position = curPt;
//charSprite.visible = YES;
[current performSelector:@selector(fade:) withObject:current.charSprite afterDelay:1];
[current reorderChild:current.charSprite z:10];
[self updateCurrentRune:currentR];
[self updateCurrentCastNum:currentP];
[self reorderChild:current z:10];
}
}
私はUITapGestureRecognizerを試してみましたが、実装しようとするすべてのことは決してうまくいきません。私のレイヤー/スプライトはそれらをジェスチャーとして追加することはできません。私はCCGrstureRecognizerについて何かを読んだり、cocos2dフォーラムで何かを読んだけど、そのクラスに関するドキュメンテーションを見つけることができず、実際にそれを使う方法も見つけられません...
私の問題を助けてくれますか?
FWIW Kobold2Dは、ジェスチャ認識装置のための超簡単なラッパを持っていますhttp://www.learn-cocos2d.com/api-ref/latest/Kobold2D/html/interface_k_k_input.html#a35f245655ed7f7329f01a1500fc1e2b6 – LearnCocos2D
ハ私は期待していませんでした私の質問にコメントするために読んでいた本の著者。 – OghmaOsiris
それから私はスペインの審問であると思う。 ;) – LearnCocos2D