2019独角兽企业重金招聘Python工程师标准>>>
新建一个地鼠的逻辑操作类:/src/Mole.js
/**
知识点:代码提示:刷新编辑器
*/
var Mole = (function(){function Mole(normalState,hitState,downY){//正常状态地鼠this.normalState = normalState;//受击状态地鼠this.hitState = hitState;//最低点的y坐标 (到编辑界面中查找)this.downY = downY;//最高点的y坐标 当前状态的y坐标this.upY = this.normalState.y;//重至this.reset();//给常态图添加点击事件 第一个是事件 第二个是执行域 第三个执行的方法this.normalState.on(Laya.Event.CLICK,this,this.hit)};var _proto = Mole.prorotype;//重值_proto.reset = function(){//隐藏this.normalState.visible = false;this.hitState.visible = false;//激活状态this.isActive = false;//显示状态this.isShow = false;//受击状态this.isHit = false;}//显示_proto.show = function(){//如果是激活了不做任何事情if(this.isActive)return ;this.isActive = true;this.isShow = true;//显示地鼠this.normalState.visible = true;//让地鼠回到最低坐标this.normalState.y = this.downY;//让地鼠缓冲出来Laya.Tween.to(this.normalState,{y:this.upY},500,Laya.Ease.backOut,Laya.Handler.create(this,this.showComplete));}//停留_proto.showComplete = function(){if(this.isShow && !this.isHit){//让地鼠停留2秒 第一个参数停留时间,第二个参数执行域,第三个是回调Laya.timer.once(2000,this,this.hide)}}//消失_proto.hide = function(){if(this.isShow && !this.isHit){this.isShow = false;Laya.Tween.to(this.normalState,{y:this.downY},300,Laya.Ease.backIn,Handler.create(this,this.reset));}}//受击_proto.hit = function (){if(this.isShow && !this.isHit){this.isShow = false;this.isHit = true;//隐藏常态图 显示受击图this.normalState.visible = false;this.hitState.visible = true;//清楚可能未被到时间的停留定时记 第一个参数是执行域 第二个参数是清楚的定时器方法Laya.timer.clear(this,this.hide);//让地鼠停留一会后消失Laya.timer.once(500,this,this.reset);}}return Mole;
})();