precisa ser capaz de armazenar 2 toques, como eu vou sobre isso eu como nenhuma idéia ...
é assim que estou fazendo um único toque
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/////checks whether the screen has been touched and stores its location and converts the coordinates to be avaible for use////
UITouch* myTouch = [touches anyObject];
CGPoint locationLeft = [myTouch locationInView: [myTouch view]];
locationLeft = [[CCDirector sharedDirector]convertToGL:locationLeft];
como eu seria capaz de armazenar o segundo toque?
desde já, obrigado
Respostas:
2 para resposta № 1Você deveria usar ccTouchBegan
(observe o singular "toque" em vez de "toques") quando precisar lidar com vários toques. (As pessoas da OMI devem simplesmente abandonar o ccTouchesBegan / Moved / Ended e apenas usar o ccTouchBegan / Moved / Ended).
Cada um dos ccTouchBegan / Moved / Ended é chamado para cada toque, o que significa que você pode facilmente diferenciar entre vários toques. Exemplo:
- (void)registerWithTouchDispatcher {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:YES];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
if (self.firstTouch == nil) {
// we got the first touch
self.firstTouch = touch;
}
else if (self.secondTouch == nil) {
// we got the second touch
self.secondTouch = touch;
}
// return YES to consume the touch (otherwise it"ll cascade down the layers)
return YES;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
if (touch == self.firstTouch) {
// we got the first touch
// do stuff
}
else if (touch == self.secondTouch) {
// we got the second touch
// do stuff
}
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
if (touch == self.firstTouch) {
// first touch ended so remove both touches
self.firstTouch = nil;
self.secondTouch = nil;
}
else if (touch == self.secondTouch) {
// second touch ended so remove touch only
self.secondTouch = nil;
}
}
0 para resposta № 2
Você já tentou iterar através dos toques como este?
for (UITouch *touch in touches){
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
location = [self convertToNodeSpace:location];