Question

J'ai quelques problèmes avec la configuration des touches pour faire glisser votre doigt vers le haut pour effectuer une action.J'essaie d'utiliser le code ci-dessous, mais il ne reconnaîtra pas les touches.

-(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]];
}

}

Il ne dit même pas "touché" lorsque je touche l'écran et les interactions utilisateur sont activées dans init.Toute aide sera appréciée !

Était-ce utile?

La solution

Dans cocos2d v3, vous devez tout remplacer ccTouchesBegan/ccTouchesMoved/ccTouchesEnded à

-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
-(void) touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event

La bonne nouvelle est que vous pouvez obtenir l'emplacement actuel du toucher en utilisant simplement la ligne suivante

CGPoint touchPos = [touch locationInNode:self];

tout cela n'est donc pas obligatoire

/*
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
*/
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top