You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm porting a bit of SkiaSharp code which combines SKBlendMode.DstIn (Destination In) and SKBlendMode.Color (blend mode color) for a drawing operation (more or less a one liner of code).
I tried to apply this on a sprite, after lots of trial and error and research I came up with this:
Create a Graphics object with the desired color and width / size of the original sprite, set blend mode 'color'
Create a local Container, add a Sprite and the Graphics object, render it on a RenderTexture
Create a Mask from the Sprite (by applying ColorOverlayFilter filter), render it on a RenderTexture
Create a new Sprite, use the blended RenderTexture as texture and the rendered mask, render it on a RenderTexture
Replace the original texture
// Blend texture with colorletoverlay=newGraphics().rect(0,0,sprite.width,sprite.height).fill(0xFF0000);overlay.blendMode="color";letcontainer=newContainer();container.addChild(newSprite({texture: newTexture({source: sprite.texture.source,frame: sprite.texture.frame})}));container.addChild(overlay);letblendedRenderTexture=RenderTexture.create({width: sprite.width,height: sprite.height,});application.renderer.render(container,{renderTexture: blendedRenderTexture});// Create mask to filter out black pixelsletmask=newSprite({texture: newTexture({source: sprite.texture.source,frame: sprite.texture.frame})});mask.filters=newColorOverlayFilter({color: 'white',alpha: 1});letrenderedTextureMask=RenderTexture.create({width: sprite.width,height: sprite.height,});application.renderer.render(mask,{renderTexture: renderedTextureMask});// Create the final textureletblendedAndMasked=newSprite(blendedRenderTexture)blendedAndMasked.mask=newSprite(renderedTextureMask);letfinalTexture=RenderTexture.create({width: sprite.width,height: sprite.height,});application.renderer.render(blendedAndMasked,{renderTexture: finalTexture});// Replace the texturesprite.texture=finalTexture;
render(container: Container, options: { renderTexture: any; }): void; is marked as obsolete, how would I replace that with render(options: RenderOptions | Container): void;?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm porting a bit of SkiaSharp code which combines SKBlendMode.DstIn (Destination In) and SKBlendMode.Color (blend mode color) for a drawing operation (more or less a one liner of code).
I tried to apply this on a sprite, after lots of trial and error and research I came up with this:
Graphics
object with the desired color and width / size of the original sprite, set blend mode 'color'Container
, add aSprite
and theGraphics
object, render it on aRenderTexture
Sprite
(by applyingColorOverlayFilter
filter), render it on aRenderTexture
RenderTexture
as texture and the rendered mask, render it on aRenderTexture
render(container: Container, options: { renderTexture: any; }): void;
is marked as obsolete, how would I replace that withrender(options: RenderOptions | Container): void;
?Beta Was this translation helpful? Give feedback.
All reactions