egret点击跳转页面

egret点击跳转页面,有这个功能?

阅读 5.9k
2 个回答

如果是外链,直接 window.location.href跳转就可以了

如果是游戏页面切换,直接移除之前的,在舞台上重新实例化一个就可以了

class Main extends egret.DisplayObjectContainer {

constructor() {
    super();   
    this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}

   private _txInfo11:egret.TextField;
   private container1;
  
private onAddToStage(event:egret.Event) {


     this.container1 = new egret.DisplayObjectContainer();
      var robot:Robot = new Robot();
     this.container1.addChild(robot);

    this._txInfo11 = new egret.TextField;
    this.addChild( this._txInfo11 );
    this._txInfo11.size = 28;
    this._txInfo11.x = 400;
    this._txInfo11.y = 10;
    this._txInfo11.text = "换页";


     var _bgInfo11:egret.Sprite = new egret.Sprite();
    this.addChildAt(_bgInfo11, this.numChildren - 1 );

   _bgInfo11.x = this._txInfo11.x;
    _bgInfo11.y = this._txInfo11.y;
   _bgInfo11.graphics.clear();
    _bgInfo11.graphics.beginFill( 0xff7f50, .5 );
    _bgInfo11.graphics.drawRect( 0, 0, this._txInfo11.width, this._txInfo11.height );
   _bgInfo11.graphics.endFill();
     _bgInfo11.touchEnabled = true;
     _bgInfo11.addEventListener( egret.TouchEvent.TOUCH_TAP, ()=>{
               if(this.contains(this.container1)){
            this.removeChild(this.container1);
          
        }else{

            this.addChild(this.container1);
             
        }
    }, this );  



}

}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题