CreateIdiom.ts 2.8 KB

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