视野(光影)实现

实现:
组件:cc.Sprite, ReactArc
ReactArc
 
const { executeInEditMode, ccclass, property } = cc._decorator;

@ccclass
@executeInEditMode
export default class ReactArc extends cc.Component {
    @property(cc.Node)
    target: cc.Node = null;

    @property
    maxRange = 0.3;
    @property
    minRange = 0.05;

    _face: cc.Sprite = null;
    get face() {
        if (!this._face) {
            this._face = this.getComponent(cc.Sprite);
        }
        return this._face;
    }

    update(dt: number) {
        if (CC_EDITOR) {
            if (cc.isValid(this.target)) {
                let sub = this.target.position.sub(this.node.position);
                let dis = sub.mag();
                let rad = cc.v2(sub).signAngle(cc.Vec2.RIGHT);
                let deg = cc.misc.radiansToDegrees(rad) + 180;

                this.face.fillRange = (1 - (dis / 500)) * (this.maxRange - this.minRange);

                if (this.face.fillRange < 0.05) {
                    this.face.fillRange = 0.05;
                }
                else if (this.face.fillRange > 0.3) {
                    this.face.fillRange = 0.3;
                }
                this.face.fillStart = (-deg / 360 - this.face.fillRange / 2);

            }
        }
    }
}
 

 

 

posted @   需要自律的人  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示