当前位置:   article > 正文

Laya 实操六:按秒移动/旋转等+缓动+TimeLine_laya.timeline.to

laya.timeline.to

按秒移动/旋转

  1. export default class Test extends Laya.Script {
  2. constructor() { super(); }
  3. private self: any = null;
  4. onAwake(){
  5. this.self = this.owner;
  6. }
  7. onUpdate(){
  8. //this.self.x += 100 * Laya.timer.delta/1000;//移动
  9. //this.self.rotation += 30 * Laya.timer.delta/1000;//旋转
  10. //斜行
  11. /*
  12. this.self.x += 100 * Laya.timer.delta/1000 * Math.cos(45 * Math.PI/180);
  13. this.self.y += 100 * Laya.timer.delta/1000 * Math.sin(45 * Math.PI/180);
  14. */
  15. }
  16. }

缓动

  1. export default class Test extends Laya.Script {
  2. constructor() { super(); }
  3. private self: any = null;
  4. onAwake(){
  5. this.self = this.owner;
  6. }
  7. onStart(){
  8. //Laya.Tween.from(this.owner,{x:500,y:500},2000,null);//位置从参数状态到当前状态
  9. //Laya.Tween.to(this.owner,{x:500,y:500},2000,null);//位置从当前状态到参数状态
  10. //Laya.Tween.to(this.owner,{x:500,y:500,rotation:180},2000,null);//位置+旋转
  11. //Laya.Tween.to(this.owner,{x:500,y:500,rotation:90,scaleX:0.2,scaleY:0.2},2000,null);//位置+旋转+缩放
  12. //停止并清理缓动
  13. //let t = Laya.Tween.from(this.owner,{x:500,y:500},5000,null);
  14. //Laya.timer.once(1000,this,function () {
  15. //t.clear();
  16. //Laya.Tween.clear(t);
  17. //Laya.Tween.clearAll(this.owner);
  18. //t.complete();//立即结束并设置到目标状态
  19. //});
  20. //加入回调
  21. /*
  22. let func = Laya.Handler.create(this,function () {
  23. console.log("ok");
  24. });
  25. Laya.Tween.from(this.owner,{x:500,y:500},2000,null,func);
  26. */
  27. //延时
  28. /*
  29. let func = Laya.Handler.create(this,function () {
  30. console.log("ok");
  31. });
  32. Laya.Tween.from(this.owner,{x:500,y:500},2000,null,func,3000);
  33. */
  34. //暂停pause
  35. //重新开始restart
  36. //暂停恢复resume
  37. //设置开始时间setStartTime
  38. //……
  39. //缓动类型
  40. //Laya.Tween.from(this.owner,{x:500,y:500},2000,Laya.Ease.backOut);
  41. //比例执行+执行次数+状态更新函数
  42. /*
  43. let t = Laya.Tween.from(this.owner,{x:700,y:500},2000,Laya.Ease.backOut);
  44. t.progress = 0.3;//比例执行
  45. t.repeat = 3;//执行次数,为0时无线循环
  46. t.update = Laya.Handler.create(this,()=>{console.log("ok")});//状态更新函数
  47. */
  48. }
  49. }

TimeLine

  1. export default class Test extends Laya.Script {
  2. constructor() { super(); }
  3. onStart(){
  4. //普通
  5. /*
  6. let tl = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},2000,null);
  7. tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
  8. //tl.play(0);//播放一次
  9. tl.play(0,true);//循环播放
  10. */
  11. //带延时
  12. /*
  13. let tl = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},2000,null);
  14. tl.to(this.owner,{scaleX:1,scaleY:1},2000,null,3000);//延时3s
  15. tl.play(0);//播放一次
  16. */
  17. //使结束
  18. /*
  19. let tl = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},2000,null);
  20. tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
  21. tl.play(0,true);
  22. Laya.timer.once(8000,this,function(){
  23. tl.destroy();//结束
  24. this.owner.scaleX = 0.5;
  25. this.owner.scaleY = 0.5;
  26. });
  27. */
  28. //带事件
  29. /*
  30. let tl = new Laya.TimeLine();
  31. tl.to(this.owner,{scaleX:0,scaleY:0},2000,null);
  32. tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
  33. tl.play(0);
  34. tl.on(Laya.Event.COMPLETE,this,function(){
  35. console.log("ok");
  36. });
  37. */
  38. //带标签
  39. /*
  40. let tl = new Laya.TimeLine();
  41. tl.to(this.owner,{scaleX:0,scaleY:0},2000,null);
  42. tl.addLabel("aaa",0);
  43. tl.on(Laya.Event.LABEL,this,function(p){
  44. console.log("o",p);
  45. });
  46. tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
  47. tl.play(0);
  48. tl.on(Laya.Event.COMPLETE,this,function(){
  49. console.log("k");
  50. });
  51. */
  52. /*
  53. let tl = new Laya.TimeLine();
  54. tl.to(this.owner,{scaleX:0,scaleY:0},2000,null);
  55. tl.addLabel("aaa",0);
  56. tl.on(Laya.Event.LABEL,this,function(p){
  57. console.log("o",p);
  58. });
  59. tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
  60. tl.play("aaa");
  61. tl.on(Laya.Event.COMPLETE,this,function(){
  62. console.log("k");
  63. });
  64. */
  65. }
  66. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/214634
推荐阅读
相关标签
  

闽ICP备14008679号