Tuesday, November 5, 2024
spot_img

Gradient Disappears when Node is opened once more – Cocos Creator


I’ve used following file to set the gradient on a node. The gradient is utilized accurately the primary time, however once I reopen the node, the background turns into white.
That is the code of ColorAssembler2D.ts file


import Logs from "./Logs";

const { ccclass, property,/* executeInEditMode,*/ requireComponent, menu } = cc._decorator;

@ccclass
// @executeInEditMode
@requireComponent(cc.RenderComponent)
@menu('i18n:MAIN_MENU.part.renderers/ColorAssembler2D-lamyoung.com')
export default class ColorAssembler2D extends cc.Part {

    @property
    non-public _whetherHorizontal: boolean = false;

    @property
    public get whetherHorizontal() {
        return this._whetherHorizontal;
    }
    public set whetherHorizontal(worth) {
        this._whetherHorizontal = worth;
        this._updateColors();
    }

    @property
    non-public _colors: cc.Shade[] = [];
    @property({ kind: [cc.Color] })
    public get colours() {
        return this._colors;
    }
    public set colours(colours) {
        this._colors = colours;
        this._updateColors();
    }

    onEnable() {
    attempt {
        cc.director.as soon as(cc.Director.EVENT_AFTER_DRAW, this._updateColors, this);
    }
    catch (e) {
        Logs.printException("Exception in ColorAssembler2D - onEnable", e);
    }
    }

    onDisable() {
    attempt {
        cc.director.off(cc.Director.EVENT_AFTER_DRAW, this._updateColors, this);
        if(this.node == null || this.node == undefined)
        {
            return;
        }        
        // this.node['_renderFlag'] |= cc['RenderFlow'].FLAG_COLOR;
    }
    catch (e) {
        Logs.printException("Exception in ColorAssembler2D - onDisable", e);
    }
    }

    begin() {
        attempt {
            this._updateColors();
        }
        catch (e) {
            Logs.printException("Exception in ColorAssembler2D - begin", e);
        }
    }

    _updateColors() {
    attempt {
        const cmp = this.node.getComponent(cc.RenderComponent);
        if (!cmp) return;
        const _assembler = cmp['_assembler'];
        if (!(_assembler instanceof cc['Assembler2D'])) return;
        const uintVerts = _assembler._renderData.uintVDatas[0];
        if (!uintVerts) return;
        const shade = this.node.shade;
        const floatsPerVert = _assembler.floatsPerVert;
        const colorOffset = _assembler.colorOffset;
        let depend = 0;
        const sp = this.node.getComponent(cc.Sprite);
        if (sp != undefined) 
        {
            /**
             * In case of ballebazzi "Congratulations_You_Won_Popup" no sprite was dragged in Sprite Part of "Panel_Base" and "Panel_Stroke" node AND ColorAssembler2D script was added to the identical node.
             * Leading to sf being null.
             * Now if we attempt to 'insetBottom' or 'insetRight' of sf as completed beneath, it throws an exception that can't learn properties of null.
             * So as a substitute of fixing within the scene we added a null examine for sf wherever it was used.
             */
            const sf = sp.spriteFrame;
            if (sp.kind == cc.Sprite.Kind.SIMPLE) {
                if (this.whetherHorizontal) {
                    for (let i = colorOffset, l = uintVerts.size; i 

Can somebody please assist me with this problem? What could possibly be the doable causes behind getting this and the way can I resolve it??

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles