egret 示例实战三:点击不同对象提升至最上层
Posted wentingc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了egret 示例实战三:点击不同对象提升至最上层相关的知识,希望对你有一定的参考价值。
实现效果:点击不同女孩提升至最上层
1.初始化对象
1 private index = 1; 2 public constructor(){ 3 super(); 4 TestIndex.instance = this; 5 //初始化三个对象 6 let girl1 = CommonFun.creatBitmapByName("girl1_png"); 7 let girl2 = CommonFun.creatBitmapByName("girl2_png"); 8 let girl3 = CommonFun.creatBitmapByName("girl3_png"); 9 girl1.y = 400; 10 girl2.y = 400; 11 girl3.y = 400; 12 girl1.x = 100; 13 girl2.x = 230; 14 girl3.x = 360; 15 girl1.touchEnabled = true; 16 girl2.touchEnabled = true; 17 girl3.touchEnabled = true; 18 this.addChildAt(girl1,this.index); 19 this.addChildAt(girl2,this.index); 20 this.addChildAt(girl3,this.index);
2.添加点击监听事件,提升对象层级
1 //为对象添加点击监听事件,设置层级 2 girl1.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{ 3 TestIndex.instance.setChildIndex(girl1,this.index+1); 4 this.index ++; 5 console.log(1 + ",index="+this.index); 6 },this); 7 girl2.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{ 8 TestIndex.instance.setChildIndex(girl2,this.index+1); 9 this.index ++; 10 console.log(2 + ",index="+this.index); 11 },this); 12 girl3.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{ 13 TestIndex.instance.setChildIndex(girl3,this.index+1); 14 this.index ++; 15 console.log(3 + ",index="+this.index); 16 },this);
3.效果
以上是关于egret 示例实战三:点击不同对象提升至最上层的主要内容,如果未能解决你的问题,请参考以下文章
egret 示例实战六:利用Timer定时器,实现钟表秒针行走效果