一.先看效果图
二,.实现原理
1.制作角色预制体,使用线性运动改变大小,透明度等(同理动画也可以完成),
onChange(speed){
let time_line = Laya.TimeLine.to(this.owner,{alpha:0,scaleX:0,scaleY:0},speed);
time_line.play();
time_line.on(Laya.Event.COMPLETE,this,function(){
this.owner.removeSelf();
})
}
2.角色移动时根据每帧不同的位置创建预制体对象
onTw(_x,_y){
var m = Laya.Pool.getItemByCreateFun("cy", this.cy_fb.create, this.cy_fb);
m.pos(_x,_y);
m.scaleX = m.scaleY = 1;
m.alpha = 1;
m.x = _x;
m.y = _y;
this.owner.addChild(m)
m.getComponent(cy).onChange(500)
}
onUpdate(){
let nowX = this.owner.getChildByName('monkey').x;
let nowY = this.owner.getChildByName('monkey').y
if(!(this.roleX == nowX && this.roleY ==nowY)){
this.onTw(this.owner.getChildByName('monkey').x,this.owner.getChildByName('monkey').y);
this.roleX = nowX
this.roleY = nowY
}
}
onMouseMove(){
this.owner.getChildByName('monkey').pos(Laya.stage.mouseX,Laya.stage.mouseY)
}