0
我不完全理解這一點,我試圖設置使用默認模板的觸摸處理,唯一的區別是我委託如何處理觸摸類的實現協議。問題是,唯一可用的kTouchPhase
是kTouchPhaseCancelled
。Kobold2d:KKInput觸摸處理使用touchPhases
-(void) update:(ccTime)delta
{
if ([input isAnyTouchOnNode:self touchPhase:KKTouchPhaseAny])
{
CCLOG(@"Touch: beg=%d mov=%d sta=%d end=%d can=%d",
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseBegan],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseMoved],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseStationary],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseEnded],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseCancelled]);
}
CCDirector* director = [CCDirector sharedDirector];
if (director.currentPlatformIsIOS)
{
[self gestureRecognition]; // Calls method pasted bellow
if ([KKInput sharedInput].anyTouchEndedThisFrame)
{
CCLOG(@"anyTouchEndedThisFrame");
}
}
- >
-(void) gestureRecognition
{
NSAssert(self.delegate != nil, @"Delegate must be non-nil");
if (input.gestureTapRecognizedThisFrame)
{
[self.delegate moveObjectToNewPosition:input];
}
然後它實現了協議,委託決定如何在moveObjectToNewPosition:
-(void) moveObjectToNewPosition:(KKInput *)input
{
//KKInput *input = [KKInput sharedInput];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CGPoint touchLocation = [input locationOfAnyTouchInPhase:KKTouchPhaseBegan];
[self touchesBegan:touchLocation];
}
- (void)touchesBegan: (CGPoint)touchLocation
{
CCLOG(@"x: %f y: %f", touchLocation.x, touchLocation.y);
}
但唯一的觸摸階段,讓我做協調是KKTouchPhaseCancelled
或KKTouchPhaseAny
...這裏發生了什麼?
好吧,我把'if(input.gestureTapRecognizedThisFrame)'改爲'input.touchesAvailable'。現在我在'[self touchesBegan:[input locationOfAnyTouchInPhase:KKTouchPhaseBegan]]中獲取touchPhaseBegan;'但是如果我對KKTouchPhaseMoved和KKTouchPhaseEnded執行相同操作,則結果不穩定 – 2013-05-13 08:45:06