i want to disable touch in Cocos2d screen. i want touch disable for 4-5 second.any one help me. thanks
Asked
Active
Viewed 538 times
4 Answers
1
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;
}

Jo Silter
- 93
- 6
0
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");
}
}

Dhrupal
- 1,863
- 1
- 23
- 38
0
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");
}

Karan Rana
- 638
- 4
- 14
0
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.

CodeSmile
- 64,284
- 20
- 132
- 217