123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { _decorator, Component, debug, director, find, instantiate, Layers, Node, NodePool, Prefab, tween, Vec3 } from 'cc';
- import { Cube_Infor, Cube_State } from './Cube_Infor';
- import { Container_Manager } from './Container_Manager';
- const { ccclass, property } = _decorator;
- @ccclass('CreateIdiom')
- export class CreateIdiom extends Component {
- count: number = 0;
- Container: Container_Manager;
- onLoad() {
- this.Container = find('Container').getComponent(Container_Manager);
- }
- update(deltaTime: number) {
- }
- nodeMoving() {
- this.node.setPosition(new Vec3(0,0.3,0));
- let startPos = this.node.position; // 起点,抛物线开始的坐标
- let middlePos = new Vec3(this.node.position.x, this.node.position.y, 0); // 中间控制点
- let destPos = new Vec3(this.node.position.x, this.node.position.y, 0); // 终点,抛物线上升顶点
- let twoBezier = (t: number, p1: Vec3, cp: Vec3, p2: Vec3) => {
- // 贝塞尔曲线计算
- let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
- let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
- // 螺旋运动计算
- let angle = t * Math.PI * 6; // 螺旋角度变化,增加圈数
- let radius = 0.5 + t * 2.5; // 螺旋半径逐渐增大
- let xOffset = Math.cos(angle) * radius; // x 轴偏移
- let zOffset = Math.sin(angle) * radius; // z 轴偏移
- // 返回最终点,带有螺旋效果
- return new Vec3(x + xOffset, y, zOffset);
- };
- let tweenDuration: number = 1.0; // 动画时长
- let createdNodes = 0; // 已生成的节点计数
- tween(this.node.position)
- .to(tweenDuration, destPos, {
- onUpdate: (target: Vec3, ratio: number) => {
- // 计算新的位置,带螺旋上升效果
- this.node.position = twoBezier(ratio, startPos, middlePos, destPos);
- // 根据进度生成新节点
- let cube =this.Container.getCube();
- if (cube != null&&cube.getComponent(Cube_Infor).state === Cube_State.live) {
- let newNode = cube;
- newNode.parent = director.getScene();
- newNode.setPosition(this.node.position);
- this.Container.nodeReferences.push(newNode);
- console.log(cube.getComponent(Cube_Infor).Text);
- }
- }
- }).start();
- }
- }
|