把这段代码添加到角色控制脚本中,再把jampBack写到update里。
//跳出窗口,从反方向跳回
jumpBack(){
if (this.node.position.x < -cc.view.getVisibleSize().width / 2) {
this.node.setPosition(cc.view.getVisibleSize().width / 2, this.node.position.y);
} else if (this.node.x > cc.view.getVisibleSize().width / 2) {
this.node.setPosition(-cc.view.getVisibleSize().width / 2, this.node.position.y);
}
}