CreateIdiom.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { _decorator, Component, debug, director, instantiate, Layers, Node, NodePool, Prefab, tween, Vec3 } from 'cc';
  2. import { Cube_Infor, Cube_State } from './Cube_Infor';
  3. import { Container } from '../core/util_class/Container';
  4. import { Container_Manager } from './Container_Manager';
  5. import { UI_Main } from '../module_game/ui/UI_Main/UI_Main';
  6. import { gui } from '../core/ui/ui';
  7. import { UI_Idioms } from '../module_game/ui/UI_Idioms/UI_Idioms';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('CreateIdiom')
  10. export class CreateIdiom extends Component {
  11. count: number = 0;
  12. onLoad() {
  13. gui.show(UI_Main);
  14. }
  15. update(deltaTime: number) {
  16. }
  17. nodeMoving() {
  18. this.node.setPosition(new Vec3(0,1.6,0));
  19. let startPos = this.node.position; // 起点,抛物线开始的坐标
  20. let middlePos = new Vec3(this.node.position.x, this.node.position.y + 2, 0); // 中间控制点
  21. let destPos = new Vec3(this.node.position.x, this.node.position.y + 4, 0); // 终点,抛物线上升顶点
  22. let twoBezier = (t: number, p1: Vec3, cp: Vec3, p2: Vec3) => {
  23. // 贝塞尔曲线计算
  24. let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
  25. let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
  26. // 螺旋运动计算
  27. let angle = t * Math.PI * 6; // 螺旋角度变化,增加圈数
  28. let radius = 0.5 + t * 1.5; // 螺旋半径逐渐增大
  29. let xOffset = Math.cos(angle) * radius; // x 轴偏移
  30. let zOffset = Math.sin(angle) * radius; // z 轴偏移
  31. // 返回最终点,带有螺旋效果
  32. return new Vec3(x + xOffset, y, zOffset);
  33. };
  34. let tweenDuration: number = 3.0; // 动画时长
  35. let createdNodes = 0; // 已生成的节点计数
  36. tween(this.node.position)
  37. .to(tweenDuration, destPos, {
  38. onUpdate: (target: Vec3, ratio: number) => {
  39. // 计算新的位置,带螺旋上升效果
  40. this.node.position = twoBezier(ratio, startPos, middlePos, destPos);
  41. // 根据进度生成新节点
  42. let cube = Container_Manager.instance.getCube();
  43. if (cube != null&&cube.getComponent(Cube_Infor).state === Cube_State.live) {
  44. let newNode = cube;
  45. newNode.parent = director.getScene();
  46. newNode.setPosition(this.node.position);
  47. Container_Manager.instance.nodeReferences.push(newNode);
  48. console.log(cube.getComponent(Cube_Infor).Text);
  49. }
  50. }
  51. }).start();
  52. }
  53. }