Reputation: 673
i want to disable touch in Cocos2d screen. i want touch disable for 4-5 second.any one help me. thanks
Upvotes: 1
Views: 558
Reputation: 638
You can disable touch and call a schedule method with time 5 sec as
setIsTouchEnabled(false);
schedule("enableTouchAfter5sec",5f);//5f is the duration after that method calls
and in enableTouchAfter5sec method enable the touch
public void enableTouchAfter5sec(float dt) {
setIsTouchEnabled(true);
unschedule("enableTouchAfter5sec");
}
Upvotes: 0
Reputation: 1873
Define one time variable
static float time;
Write below code when you want to disable touch screen
this.schedule("touchdiablefor5sec",1f);
Now write below method
public void touchdiablefor5sec(float dt) {
//first disable screen touch
this.setIsTouchEnabled(false);
time= time+1;
// if 5 second done then enable touch
if(time==5)
{
this.setIsTouchEnabled(true);
//unschedule the touchdiablefor5sec scheduler
this.unschedule("touchdiablefor5sec");
}
}
Upvotes: 0
Reputation: 93
Also you can set a custom timer:
static Integer time = 100;
and count down when you need it:
time--;
...
if (time <= 0) {
setTouchEnabled = false;
//you can also reset time here: time = 100;
} else {
setTouchEnabled = true;
}
Upvotes: 1
Reputation: 64478
Use a bool value to toggle your touch code on/off.
if (touchEnabled)
{
// do touch code
}
else
{
// not …
}
Somewhere else, disable touch temporarily:
// accept no touches from now on
touchEnabled = false;
I leave re-enabling the touches up to you.
Upvotes: 0