• laya---直线移动


    1. beginMove(result: Function) {
    2. let width;
    3. let height;
    4. let ratio;
    5. let isXmax;
    6. if (this.ownFwy_cp.x > 0 && this.moveTaget.x > 0) {
    7. if (this.ownFwy_cp.x > this.moveTaget.x) {
    8. width = this.ownFwy_cp.x - this.moveTaget.x;
    9. } else {
    10. width = this.moveTaget.x - this.ownFwy_cp.x;
    11. }
    12. } else if ((this.ownFwy_cp.x > 0 && this.moveTaget.x < 0) || (this.ownFwy_cp.x < 0 && this.moveTaget.x > 0)) {
    13. width = Math.abs(this.ownFwy_cp.x) + Math.abs(this.moveTaget.x);
    14. }
    15. else {
    16. if (Math.abs(this.ownFwy_cp.x) > Math.abs(this.moveTaget.x)) {
    17. width = Math.abs(this.ownFwy_cp.x) - Math.abs(this.moveTaget.x);
    18. } else {
    19. width = Math.abs(this.moveTaget.x) + Math.abs(this.ownFwy_cp.x);
    20. }
    21. }
    22. if (this.ownFwy_cp.y > 0 && this.moveTaget.y > 0) {
    23. if (this.ownFwy_cp.y > this.moveTaget.y) {
    24. height = this.ownFwy_cp.y - this.moveTaget.y;
    25. } else {
    26. height = this.moveTaget.y - this.ownFwy_cp.y;
    27. }
    28. } else if ((this.ownFwy_cp.y > 0 && this.moveTaget.y < 0) || (this.ownFwy_cp.y < 0 && this.moveTaget.y > 0)) {
    29. height = Math.abs(this.ownFwy_cp.y) + Math.abs(this.moveTaget.y);
    30. }
    31. else {
    32. if (Math.abs(this.ownFwy_cp.y) > Math.abs(this.moveTaget.y)) {
    33. height = Math.abs(this.ownFwy_cp.y) - Math.abs(this.moveTaget.y);
    34. } else {
    35. height = Math.abs(this.moveTaget.y) + Math.abs(this.ownFwy_cp.y);
    36. }
    37. }
    38. if (width > height) {
    39. ratio = width / height;
    40. isXmax = true;
    41. } else {
    42. ratio = height / width;
    43. isXmax = false;
    44. }
    45. console.log("w:" + width + "...h:" + height + "...r:" + ratio);
    46. Laya.timer.frameLoop(1, this, () => {
    47. if(isXmax){
    48. if (this.ownFwy_cp.x > this.moveTaget.x) {
    49. this.ownFwy_cp.x -= this.moveSpeed;
    50. if (this.ownFwy_cp.x <= this.moveTaget.x) {
    51. this.ownFwy_cp.x = this.moveTaget.x;
    52. }
    53. } else if (this.ownFwy_cp.x < this.moveTaget.x) {
    54. this.ownFwy_cp.x += this.moveSpeed;
    55. if (this.ownFwy_cp.x > this.moveTaget.x) {
    56. this.ownFwy_cp.x = this.moveTaget.x;
    57. }
    58. }
    59. if (this.ownFwy_cp.y > this.moveTaget.y) {
    60. this.ownFwy_cp.y -= this.moveSpeed/ratio;
    61. if (this.ownFwy_cp.y < this.moveTaget.y) {
    62. this.ownFwy_cp.y = this.moveTaget.y;
    63. }
    64. } else if (this.ownFwy_cp.y < this.moveTaget.y) {
    65. this.ownFwy_cp.y += this.moveSpeed/ratio;
    66. if (this.ownFwy_cp.y > this.moveTaget.y) {
    67. this.ownFwy_cp.y = this.moveTaget.y;
    68. }
    69. }
    70. }else{
    71. if (this.ownFwy_cp.x > this.moveTaget.x) {
    72. this.ownFwy_cp.x -= this.moveSpeed/ratio;
    73. if (this.ownFwy_cp.x <= this.moveTaget.x) {
    74. this.ownFwy_cp.x = this.moveTaget.x;
    75. }
    76. } else if (this.ownFwy_cp.x < this.moveTaget.x) {
    77. this.ownFwy_cp.x += this.moveSpeed/ratio;
    78. if (this.ownFwy_cp.x > this.moveTaget.x) {
    79. this.ownFwy_cp.x = this.moveTaget.x;
    80. }
    81. }
    82. if (this.ownFwy_cp.y > this.moveTaget.y) {
    83. this.ownFwy_cp.y -= this.moveSpeed;
    84. if (this.ownFwy_cp.y < this.moveTaget.y) {
    85. this.ownFwy_cp.y = this.moveTaget.y;
    86. }
    87. } else if (this.ownFwy_cp.y < this.moveTaget.y) {
    88. this.ownFwy_cp.y += this.moveSpeed;
    89. if (this.ownFwy_cp.y > this.moveTaget.y) {
    90. this.ownFwy_cp.y = this.moveTaget.y;
    91. }
    92. }
    93. }
    94. if (this.ownFwy_cp.x == this.moveTaget.x && this.ownFwy_cp.y == this.moveTaget.y) {
    95. Laya.timer.clearAll(this);
    96. result(true);
    97. }
    98. });
    99. }

  • 相关阅读:
    idea插件开发- hello world
    Kotlin 学习笔记(七)operator约定
    2023京东口腔护理赛道行业数据分析(京东销售数据分析)
    Airtest的控制手机滑动位置偏差修正方法总结
    一个奇葩的线上问题,导致我排查了一天
    音视频技术应用方向概述
    深度测评FL Studio性能,多年Fl Studio使用感受分享
    操作系统 一个进程通过内核事件 来控制另一个线程的结束
    STM32F1网络编程-HTTP服务器(基于W5500网卡)
    分享一下开发回收废品小程序的步骤
  • 原文地址:https://blog.csdn.net/lalate/article/details/126509886