I’m trying to show a simple Quit the game dialog, with a yes and no button when either escape, backspace or the back key is pressed like this:
if ('keyboard' in cc.sys.capabilities ) {
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
onKeyReleased: function(keycode, event) {
if (keycode == cc.KEY.back || keycode == cc.KEY.backspace || keycode == cc.KEY.escape) {
this.addChild(new ExitGameLayer(this._end));
}
}.bind(this)
}, this);
}
however once the ExitGameLayer
is visible on screen, any touches, mouse clicks or keyboard goes through to the layer which created/added the ExitGameLayer
.
I’ve tried to stop propagation and swallow touches in my ExitGameLayer
like this to no avail:
if ('touches' in cc.sys.capabilities ) {
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
return true;
}
}, this);
} else if ('mouse' in cc.sys.capabilities ) {
cc.eventManager.addListener({
event: cc.EventListener.MOUSE,
onMouseDown: function(event) {
event.stopPropagation = true;
}
}, this);
}
if ('keyboard' in cc.sys.capabilities ) {
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
onKeyPressed: function(keycode, event) {
event.stopPropagation = true
}
}, this);
}
I’m really baffled as to why this is so hard! Please help before I rip my hands off.