Sair
  • Comunidade global
    • Idioma:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Masking a bitmap image createjs

Explorador ,
Oct 22, 2024 Oct 22, 2024

I'm trying to develop a scratchcard effect by using the cursor to scratch and reveal an image.
The code below works for painting over the bitmap but I'd like to convert the painted lines to a mask that reveals the image. I'm wanting "Brush" to be the mask and "ImageToMask" is the bitmap.

Can anyone help?

 

var MDown = false;
var Canvas = document.getElementById('canvas2');
var Brush = Canvas.getContext('2d');
var BG = new lib.MaskedContent();
stage.addChild(ImageToMask);   
Canvas.onselectstart = function () {
    return false;
};
Canvas.onmousedown = function (e) {
    MDown = true;
    Brush.lineWidth = 80;
    Brush.lineCap = 'round';
    Brush.beginPath();
    Brush.moveTo(e.pageX - Position(Canvas)
        .left, e.pageY - 5);
}
Canvas.onmouseup = function () {
    MDown = false;
};
Canvas.onmousemove = function (e) {
    if (MDown) {
        Brush.lineTo(e.pageX - Position(Canvas).left, e.pageY - 5);
        Brush.stroke();
    }
}
function Position(el) {
    var position = {
        left: 0,
        top: 0
    };
    return position;
}

 

785
Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines

correct answers 1 resposta correta

Community Expert , Oct 23, 2024 Oct 23, 2024

Hi.

 

Please check this example out.
https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/scratch

 

Regards,

JC

Traduzir
Community Expert ,
Oct 23, 2024 Oct 23, 2024

Hi.

 

Please check this example out.
https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/scratch

 

Regards,

JC

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Explorador ,
Oct 23, 2024 Oct 23, 2024

Amazing! I think I could tailor that code to what I'm trying to achieve.
Thanks so much.

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

Great! You're welcome.

 

Please let us know if you need more help.

 

Regards,

JC

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Explorador ,
Oct 28, 2024 Oct 28, 2024

Thanks again for the code, I manged to mostly tailor it to my requirements and it's working well. I noticed that the scratch area is the bounds of the stage so var minProgressToReveal triggers once a percentage of the whole stage is scratched.

I have a rotated rectangle that I want to be the scratchable area only (see attached image), not the whole stage. I would like minProgressToReveal to trigger once a percentage of the blue rectangle is scratchedIs there an easy way to do this or will it require changing a lot of the code? 

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Hey, @Rob_NZ!

 

Totally forgot. Really sorry.

Have you found a solution?

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Explorador ,
Oct 31, 2024 Oct 31, 2024
MAIS RECENTE

Hey, not a problem.  No, I didn't find a solution. 

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines