1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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,1.6,0));
- let startPos = this.node.position; // 起点,抛物线开始的坐标
- let middlePos = new Vec3(this.node.position.x, this.node.position.y+1, 0); // 中间控制点
- let destPos = new Vec3(this.node.position.x, this.node.position.y+2, 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 = 1.0 + t * 1.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 = 2.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);
- }
- }
- }).call(()=>{
- this.Container.canTouch=true;
- }).start();
- }
- }
|