Jump to content

Masking black SVG image to create a color


ansros705
 Share

Recommended Posts

Hi guys,

I think I have problem how masking in PIXIjs works.

I have this image of black horse Flat_racing_clipart.svg

And I would like to use masking in order to give it the color.

Here is my code so far:

const app = new PIXI.Application({backgroundColor: 0xFFFFFF})

document.body.appendChild(app.view)

PIXI.loader.add('assets/horse.png').load(() => {
  const horse_sprite = new PIXI.Sprite(PIXI.loader.resources['assets/horse.png'].texture)
  const horse_mask = new PIXI.Graphics()
  horse_square.beginFill(0xFFaaFF)
  horse_square.drawRect(0, 0, 130, 130)
  horse_square.endFill()
  
  horse_mask.mask = horse // I can see the horse and the square if I comment this out
  
  app.stage.addChild(horse_mask)
  app.stage.addChild(horse_sprite)
})

It's not working, I can't see anything, not a horse nor the square.

Thanks

Link to comment
Share on other sites

Masking works both by alpha and red channel. For black color, red channel is 0. 

How to solve it, 3 ways:

1. Make your horse white.

2. Make your horse white AND use "tint" attribute instead of using it as a mask for a square. Its significantly faster.

3. hard, rebuild pixi so it accepts masks of any color:

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...