ccc 3d无尽地图实现代码

149 阅读1分钟

在做向前的跑酷时,经常要用到无尽地图,下面是无尽地图的实现代码: `import { _decorator, Component, Node, instantiate, v3 } from "cc";

const { ccclass, property } = _decorator;

\

@ccclass("roadMgr")

export class roadMgr extends Component {

start () {

    let road = this.node.children[0];

    for (let i = 0; i < 10; i++) {

    let r: Node = instantiate(road);

    this.node.addChild(r);

    r.setPosition(v3(0, 0, i * 600));

    }

}



update (deltaTime: number) {

    if (this.node.getPosition().z < -600) {

        this.node.setPosition(0, 0, 0);

    }

    let pos = this.node.getPosition();

    pos.z -= 3000 * deltaTime;

    this.node.setPosition(pos);

}

}`