[寄了个鸡]已放在壁纸引擎创意工坊

嗯嗯,谢谢提醒,我看到了呢,也已经付费购买了。但是那个只有关卡部分的算法,没有楼主这个鸡场一群鸡的实现,主要想向楼主请教下这个哈

一群鸡…其实就是画圆三个圆,加个tween动画…最后鸡群根据Y轴排个序…

我发代码吧…
“chicken_circle.ts”

import { _decorator, Component, Node, Vec2, Vec3, tween } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('yang_circle')
export class yang_circle extends Component {

    @property({
        type: Node,
        tooltip: "鸡群父节点"
    })
    chicken_parent: Node = null;

    @property({
        tooltip: "鸡群中心点"
    })
    center_v2: Vec2 = new Vec2(0, 0);

    @property({
        tooltip: "鸡群间隔角度"
    })
    chicken_angular: number = 5;

    start() {
        this.show_chicken_circle();
    }

    update(deltaTime: number) {
    }

    /** 显示 鸡圈 */
    show_chicken_circle() {
        this.chicken_parent.children.forEach((element: Node, index: number) => {
            if (index < 6) {
                this.set_point_on_circle(index * (360 / 6), element, 0.2, 100);
            } else if (index < 18) {
                this.set_point_on_circle(index * (360 / 12), element, 0.4, 200);
            } else if (index < 36) {
                this.set_point_on_circle(index * (360 / 18), element, 0.6, 300);
            }
        });
        // 排序渲染层级
        this.sort_children();
    }

    /**
     * 排列子节点
     * @param jiaodu   角度
     * @param _node     节点
     * @param _delay_time   等待时间
     * @param _ani_radius   半径
     */
    set_point_on_circle(jiaodu: number, _node: Node, _delay_time: number = 0, _ani_radius: number = 0) {
        // 根据时间,计算角度,的弧度值  弧度 = 角度* (2 * Math.PI / 360);
        var new_hudu = jiaodu * (2 * Math.PI / 360);
        // 根据弧度(角度),半径,计算坐标点
        var _x = Math.sin(new_hudu) * _ani_radius;
        var _y = Math.cos(new_hudu) * _ani_radius;
        // 将节点设置在该位置
        _node.setPosition(new Vec3(_x, _y, 0));
        // 播放动画,从小变大
        _node.setScale(new Vec3(0, 0, 1));
        tween()
            .target(_node)
            .delay(_delay_time)
            .to(0.1, { scale: new Vec3(1, 1, 1) })
            .to(0.1, { scale: new Vec3(0.9, 0.9, 1) })
            .start()
    }

    /**
     * 根据Y值设置zindex
     */
    sort_children() {
        var _ch: Node[] = [].concat(this.chicken_parent.children);
        _ch.sort(function (a, b) {
            if (a.position.y < b.position.y) {
                return 1
            } else {
                return -1
            }
        });
        _ch.forEach((element, index) => {
            element.setSiblingIndex(index);
        });
    }
}

小黑子,露出鸡脚了

感谢!照着折腾了半天总算是搞出来了

真的闲…

鸽鸽下的蛋你别吃

首页能分享下吗

界面布局很简单,就鸡群转圈动画需要用到计算:

<chicken_ani.ts>

import { _decorator, Component, Node, Vec2, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('chicken_ani')
export class chicken_ani extends Component {

@property({
    type: Node,
    tooltip: "鸡群父节点"
})
chicken_parent: Node = null;

@property({
    tooltip: "鸡群中心点"
})
center_v2: Vec2 = new Vec2(0, 0);

@property({
    tooltip: "鸡群动画半径"
})
ani_radius: number = 500;

@property({
    tooltip: "鸡群间隔角度"
})
chicken_angular: number = 5;

@property({
    tooltip: "鸡群角速度\n如:每秒10度"
})
ani_angular_speed: number = 10;

@property({
    tooltip: "节点方向矫正"
})
node_y_change: boolean = false;

/** 累计时间,最大3600秒 */
all_time = 0;

start() {
}

update(deltaTime: number) {
    this.update_chicken_ani(deltaTime);
}

/**
 * 播放转圈动画
 */
update_chicken_ani(deltaTime: number) {
    // 根据累计时间,计算当前每只鸡的实时位置,并旋转方向
    this.all_time += deltaTime;
    this.chicken_parent.children.forEach((element, index) => {
        if (element != null && element.isValid) {
            // 每个节点相距第一个额外需要的时间
            var addtime = (this.chicken_angular / this.ani_angular_speed) * index;
            this.set_point_on_circle(this.all_time + addtime, element);
        }
    });
    this.sort_children();
}

set_point_on_circle(_time: number, _node: Node) {
    // 根据时间,计算角度,的弧度值  弧度 = 角度* (2 * Math.PI / 360);
    var new_hudu = (_time * this.ani_angular_speed * 1000) / 1000 * (2 * Math.PI / 360);
    // 根据弧度(角度),半径,计算坐标点
    var _x = Math.sin(new_hudu) * this.ani_radius;
    var _y = Math.cos(new_hudu) * this.ani_radius;
    // 将节点设置在该位置
    _node.setPosition(new Vec3(_x, _y, 0));
    // 根据Y值的正负设置节点方向
    var change: Vec3 = new Vec3(1, 1, 1);
    if (_y >= 0) {
        change.x *= -1;
    }
    if (this.node_y_change) {
        change.x *= -1;
    }
    _node.setScale(change);
}

/**
 *  根据Y值设置zindex
 */
sort_children() {
    //
    var _ch: Node[] = [].concat(this.chicken_parent.children);
    _ch.sort(function (a, b) {
        if (a.position.y < b.position.y) {
            return 1
        }else{
            return -1
        }
    });
    _ch.forEach((element, index) => {
        element.setSiblingIndex(index);
    });
}
}

这个游戏出吗

[寄了个鸡] 预览地址已修改为ipv6网址:
http://gnexi.cn:82/jilegeji/
在ipv6网络或流量环境下访问