Cocos2D iPhone V3.0 - 작업 수행을 위해 스 와이프
-
21-12-2019 - |
문제
액션을 수행하기 위해 터치를 설정하는 데 문제가있는 문제가 있습니다.아래 코드를 사용하려고 노력하고 있지만 촉감을 인식하지 못합니다.
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
//Swipe Detection Part 1
firstTouch = location;
CCLOG(@"touched");
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
//Swipe Detection Part 2
lastTouch = location;
//Minimum length of the swipe
float swipeLength = ccpDistance(firstTouch, lastTouch);
CCActionJumpTo *jump1 = [CCActionJumpTo actionWithDuration:2 position:ccp(self.contentSize.width*.4,self.contentSize.height*.1) height:self.contentSize.height*.5 jumps:1];
[_fufunaken runAction:[CCActionRepeat actionWithAction:jump1 times:1]];
//Check if the swipe is an up swipe and long enough
if (firstTouch.y > lastTouch.y && swipeLength > 60) {
[_fufunaken runAction:[CCActionRepeatForever actionWithAction:jump1]];
}
}
.
화면을 터치하면 "Touched"라는 메시지가 표시되지 않으며 사용자 상호 작용이 init에서 활성화되어 있습니다.어떤 도움이 모든 도움이 될 것입니다!
해결책
cocos2d v3에서 모든 ccTouchesBegan/ccTouchesMoved/ccTouchesEnded
를
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
-(void) touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event
.
좋은 소식은 다음 줄을 사용하여 터치의 현재 위치를 얻을 수 있다는 것입니다.
CGPoint touchPos = [touch locationInNode:self];
.
이 모든 것은 필요하지 않습니다
/*
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
*/
. 제휴하지 않습니다 StackOverflow