• 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. }

  • 相关阅读:
    【CSS】CSS实现水平垂直居中
    day3 ARM
    百万级别或以上的数据如何删除
    ​怎么保留硬盘数据合并分区 ,如何才能合并且不丢失数据
    第一季:8spring支持的常用数据库事务传播属性和事务隔离级别【Java面试题】
    实用调试技巧(2)
    Android Studio 的android.jar文件在哪儿
    uniapp app或微信小程序项目使用gite仓库中的图片
    写一点什么吧
    算法:包含min函数的栈
  • 原文地址:https://blog.csdn.net/lalate/article/details/126509886