Cocos2d iPhone v3.0 – Nach oben wischen, um eine Aktion auszuführen
-
21-12-2019 - |
Frage
Ich habe einige Probleme beim Einrichten von Berührungen zum Wischen nach oben, um Aktionen auszuführen.Ich versuche, den folgenden Code zu verwenden, aber er erkennt die Berührungen nicht.
-(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]];
}
}
Es wird nicht einmal „berührt“ angezeigt, wenn ich den Bildschirm berühre, und in init sind Benutzerinteraktionen aktiviert.Wir freuen uns über jede Hilfe!
Lösung
In cocos2d v3 müssen Sie alle ersetzen ccTouchesBegan/ccTouchesMoved/ccTouchesEnded
Zu
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
-(void) touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event
Die gute Nachricht ist, dass Sie die aktuelle Position der Berührung einfach über die folgende Zeile ermitteln können
CGPoint touchPos = [touch locationInNode:self];
All dies ist daher nicht erforderlich
/*
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
*/
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow