分享,一个简单的视野(光影)实现。

效果:
2021-12-02_22-10-33
2021-12-02_22-14-52-2

实现:
组件: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);

            }
        }
    }
}

44赞

大佬牛逼,打 call!

1赞

疯狂call

大佬真厉害!

感谢大佬分享

感谢大佬分享

1赞

大佬太强了吧

大佬简单实用

大佬真厉害!

昨天在群聊里看到这个效果,大佬666666 :smile:

demo不扔上来吗。。

感谢大佬充实我的收藏夹 :rofl:

战略插眼~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mark!

大佬大佬 :heart_eyes: :heart_eyes:

mark!

厉害啊,处处有大佬!!!

传个demo?

mark!

mark!