If the user has not touched the screen for a specific time, I have to do a particular action. How I can do that in Cocos2d?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could subclass your UIView and override
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event.This method is called very early in the responder chain and allows you to detect a touch anywhere in the view.
Once you detect a touch, you reset a timer, so that either a new touch event comes in before the timer fires, or the timer fires.
When the timer fires, you execute your particular action.
A similar approach can be followed by subclassing
UIWindowand then overriding-(void)sendEvent:(UIEvent *)event. This has the advantage of not being related to a view, but to the whole window of your app and being called even earlier in the responder chain.