egret实现一个图片加载的效果
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了egret实现一个图片加载的效果相关的知识,希望对你有一定的参考价值。
用白鹭引擎实现一个效果:一个图片刚加载出来的时候是模糊效果的,然后慢慢变的清晰!求代码
预加载图片是提高用户体验的一个很好方法。图片预先加载到浏览器中,这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速、无缝地发布,也可帮助用户在浏览网站内容时获得更好的用户体验。示例代码:functionloadImage(url,callback)varimg=newImage();//创建一个Image对象,实现图片的预下载img.src=url;if(img.complete)//如果图片已经存在于浏览器缓存,直接调用回调函数callback.call(img);return;//直接返回,不用再处理onload事件img.onload=function()//图片下载完毕时异步调用callback函数。callback.call(img);//将回调函数的this替换为Image对象;;追问回答的驴唇不对马嘴
参考技术A Egret 白鹭引擎实践 CSDN上有相关教程egret 示例实战六:利用Timer定时器,实现钟表秒针行走效果
1.建立一个圆和一根指针形状
1 let circle = new egret.Shape(); 2 circle.graphics.lineStyle(5,0x000000,1,true); 3 circle.graphics.drawCircle(0,0,170); 4 circle.graphics.endFill(); 5 circle.x = Main.instance.stage.stageWidth/2; 6 circle.y = Main.instance.stage.stageHeight/2; 7 this.addChild(circle); 8 9 this.pointer = new egret.Shape(); 10 this.pointer.graphics.beginFill(0xFF9900,1); 11 this.pointer.graphics.drawRect(0,0,160,5); 12 this.pointer.graphics.endFill(); 13 this.pointer.anchorOffsetY = this.pointer.height/2; 14 this.pointer.x = Main.instance.stage.stageWidth/2; 15 this.pointer.y = Main.instance.stage.stageHeight/2; 16 this.addChild(this.pointer);
2.添加Timer计时器,每秒钟走1格,走60格走完一圈
1 this.timer = new egret.Timer(1000,0); this.timer.addEventListener(egret.TimerEvent.TIMER,this.timerFun,this); 2 this.timer.start();
1 private timerFun(){ 2 this.pointer.rotation += 6; 3 // console.log(‘this.pointer.rotation = ‘+this.pointer.rotation); 4 }
3.效果
以上是关于egret实现一个图片加载的效果的主要内容,如果未能解决你的问题,请参考以下文章