Hi… new question
how is the correct way to implement the back button event in cocos creator? now don’t works…
this is the code:
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
…
onKeyUp(event) {
if (event.keyCode === cc.macro.KEY.back) {
this.emit();
}
else if (event.keyCode === cc.macro.KEY.backspace) {
this.emit();
}
else if (event.keyCode === cc.macro.KEY.escape) {
this.emit();
}
},
on PC works fine… on android nothing
what we wrong? may be missing something to init?
Many thanks for help,
Stefano
What is your version of CocosCreator?
I just ran a test using vivo x7plus
and there were no problems.
do you have used my same code?
const {ccclass, property} = cc._decorator;
@ccclass
export default class Helloworld extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
start () {
// init logic
this.label.string = this.text;
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
}
onKeyUp (event) {
switch (event.keyCode) {
case cc.macro.KEY.back:
this.label.string = "input back";
break;
}
}
}
yes it is same
only one thing is different we use javascript and not typescript…
we have resolved with this…
SDKWrapper.getInstance().onBackPressed();
AppActivity app = (AppActivity) SDKWrapper.getInstance().getContext();
app.runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxJavascriptJavaBridge.evalString("cc.onBackPressed();");
}
});
with a our function… strange…