如何访问 sprite 二维上下文?

How to get access to sprite 2D context?

是否可以在 sprite 级别而不是整个 canvas 获得 CanvasRenderingContext2D? 有没有人试图访问它?有什么想法吗?

我试过了:

child.addEventListener(RenderEvent.RENDER_CANVAS, function(event)
        {
            var renderer:openfl.display.DisplayObjectRenderer = event.renderer;         
            var ctx:CanvasRenderingContext2D = renderer.context;
            ctx.shadowBlur = 20;
            ctx.shadowColor = "black";
        });

但是,我收到错误消息:

openfl.display.DisplayObjectRenderer has no field context

如何访问精灵的 CanvasRenderingContext2D?

尝试将 renderer 转换为 CanvasRenderer:


child.addEventListener(RenderEvent.RENDER_CANVAS, function(event)
        {
            var renderer:openfl.display.CanvasRenderer = cast(event.renderer);         
            var ctx:CanvasRenderingContext2D = renderer.context;
            ctx.shadowBlur = 20;
            ctx.shadowColor = "black";
        });