23.5 C
Brasília
segunda-feira, dezembro 23, 2024

Gradiente desaparece quando o nó é aberto novamente – Cocos Creator


Usei o seguinte arquivo para definir o gradiente em um nó. O gradiente é aplicado corretamente na primeira vez, mas quando abro o nó novamente, o fundo fica branco.
Este é o código do arquivo ColorAssembler2D.ts


import Logs from "./Logs";

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

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

    @property
    personal _whetherHorizontal: boolean = false;

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

    @property
    personal _colors: cc.Shade() = ();
    @property({ kind: (cc.Shade) })
    public get colours() {
        return this._colors;
    }
    public set colours(colours) {
        this._colors = colours;
        this._updateColors();
    }

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

    onDisable() {
    strive {
        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() {
        strive {
            this._updateColors();
        }
        catch (e) {
            Logs.printException("Exception in ColorAssembler2D - begin", e);
        }
    }

    _updateColors() {
    strive {
        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 colour = this.node.colour;
        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 accomplished beneath, it throws an exception that can't learn properties of null.
             * So as an alternative of adjusting within the scene we added a null test 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 < l; i += floatsPerVert) {
                        if (countpercent2 == 0)  colour)('_val');
                        
                        else  colour)('_val');
                        
                        depend++;
                    }
                }
                else {
                    for (let i = colorOffset, l = uintVerts.size; i < l; i += floatsPerVert) {
                        if (Math.ground(depend/2) == 0)  colour)('_val');
                        
                        else  colour)('_val');
                        
                        depend++;
                    }
                }
            }
            else if (sp.kind == cc.Sprite.Kind.SLICED) {
                if (this.whetherHorizontal) {
                    for (let i = colorOffset, l = uintVerts.size; i < l; i += floatsPerVert) {
                        if (countpercent4 == 0)  colour)('_val');
                        
                        else if (countpercent4 == 1) {
                            let tempColor:cc.Shade;
                            if(sf!=null && sf!=undefined)
                             colour)('_val');
                            
                        }
                        else if (countpercent4 == 2) {
                            let tempColor:cc.Shade = new cc.Shade();
                            if(sf!=null && sf!=undefined)
                            
                        }
                        else  colour)('_val');
                        
                        depend++;
                    }
                }
                else {
                    for (let i = colorOffset, l = uintVerts.size; i < l; i += floatsPerVert) {

                        if (Math.ground(depend/4) == 0)  colour)('_val');
                        
                        else if (Math.ground(depend/4) == 1) {
                            let tempColor:cc.Shade;
                            if(sf!=null && sf!=undefined)
                            
                        }
                        else if (Math.ground(depend/4) == 2) {
                            let tempColor:cc.Shade = new cc.Shade();
                            if(sf!=null && sf!=undefined)
                             colour)('_val');
                            
                        }
                        else  colour)('_val');
                        
                        depend++;
                    }
                }
            }
        }


        const lb = this.node.getComponent(cc.Label);
        if (lb != undefined) {
            if (this.whetherHorizontal) {
                for (let i = colorOffset, l = uintVerts.size; i < l; i += floatsPerVert) {
                    if (countpercent2 == 0) 
                    else  colour)('_val');
                    
                    depend++;
                }
            }
            else {
                for (let i = colorOffset, l = uintVerts.size; i < l; i += floatsPerVert) {
                    if (Math.ground(depend/2) == 0) 
                    else  colour)('_val');
                    
                    depend++;
                }
            }
        }
    }
    catch (e) {
        Logs.printException("Exception in ColorAssembler2D - _updateColors", e);
    }   
    }


}

Alguém pode me ajudar com esse problema? Quais podem ser as possíveis razões por trás disso e como posso resolver?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

0FansLike
0FollowersFollow
0SubscribersSubscribe
- Advertisement -spot_img

Latest Articles