How can I disable the touch detection within the action that running, because I don't want the character flying in the sky like a superman if the player clicking and clicking within the action, the character will never land if they keep clicking. I found the method "isDone", is that relate to this method?? player click -> action(cannot click within the action) -> action finish -> click again..... that's what i want~
-
17Seriously, what? – marcc Jul 09 '09 at 05:28
-
21Now I want to make a Superman game too. – Nosredna Jul 09 '09 at 05:29
8 Answers
This is the best answer to your question:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];

- 2,336
- 5
- 31
- 40

- 16,120
- 23
- 124
- 161
Disable user interactions in your view till the action completes and then enable it again.
To disable touch
[self.view setUserInteractionEnabled:NO];
To enable touch
[self.view setUserInteractionEnabled:YES];
Please try and be a bit more concise of what you want the next time.

- 70,519
- 61
- 198
- 274
Just gonna make a wild assumption that you're talking about the specific Action class in Cocos2D. If that's true, then you should know that every Action has an "isDone" Bool you can check to see if it's done. Let me know if that's what you're asking and I'll post an example, but there's a huge chance you could be talking about something else because your wording is so confusing ;)

- 844
- 7
- 10
You could always put a transparent UIView over top of the area you want to "disable" tap input for, have it listen for taps, and have it ignore them. Remove the UIView (or hide it) when you want input to be listened to again.

- 1,321
- 13
- 21
-
Dave, how do you "disable" tap? have it listen for taps, and have it ignore them? – eugene Sep 11 '11 at 17:00
-
A button is a bit more efficient at this. To make it "invisible", just make it not highlight, the XIB option is adjustsWhenHighlighted, but the option name is different. +1 for Apple's lack of a standard name scheme! This method is handy for disabling custom UI (games usually) – Stephen J Jul 18 '12 at 16:15
Why don't you use some kind of (simple version) boolean to remember i.e. isInAction = true and after the action finished isInAction = false...
So when someone clicks, u use something like
if (!isInAction) {
isInAction=true;
try {
doYourAction;
} catch {
...
} finally {
isInAction=false;
}
}
// The Code is some kind of pseudocode, because I haven't yet programmed for the IPhone, just to visualize what I mean.

- 17,766
- 13
- 58
- 65
Perhaps I didn't understand your question but is this what you're looking for?
- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[Superman Fly];
self.isTouchEnabled = NO;
}
- (void)SupermanLanded{
self.isTouchEnabled = YES;
}

- 2,336
- 5
- 31
- 40

- 363
- 4
- 14