egret 底层渲染代码解析

渲染其实渲染的是 $renderNode
比如 Bitmap 他的 $renderNode 就是 BitmapNode
Label 对应 TextNode
Sprite 对应 GraphicsNode
Image 对应 NormalBitmapNode
Mesh 对应 MeshNode

一共有以下几种
BitmapNode
TextNode
GraphicsNode
GroupNode
MeshNode
NormalBitmapNode

这些node 都继承自 RenderNode
而 RenderNode 这个类是这样的

class RenderNode {
    
    
        /**
         * 节点类型..
         */
        type: number;
        /**
         * 绘制数据
         */
        drawData: any[];
        /**
         * 绘制次数
         */
        protected renderCount: number;
        /**
         * 在显示对象的$updateRenderNode()方法被调用前,自动清空自身的drawData数据。
         */
        cleanBeforeRender(): void;
        $getRenderCount(): number;
    }

以 BitmapNode 为例
他有一个 drawImage 方法

 BitmapNode.prototype.drawImage = function (sourceX, sourceY, sourceW, sourceH, drawX, drawY, drawW, drawH) {
    
    
    this.drawData.push(sourceX, sourceY, sourceW, sourceH, drawX, drawY, drawW, drawH);
    this.renderCount++;
};

可以看到 参数都传到 drawData 里了

猜你喜欢

转载自blog.csdn.net/qq_38913715/article/details/134651692