These are chat archives for pixijs/pixi.js

12th
Oct 2015
hugohil
@hugohil
Oct 12 2015 16:28
Hi there !
I have a question about canvas based texture mask
I keep getting a Cannot read property '0' of undefined error :/
I have a PIXI.Sprite.fromImage as background and a PIXI.Texture.fromCanvas as mask
well, I should put this in a codepen
brb :D
hugohil
@hugohil
Oct 12 2015 16:59
var stage = new PIXI.Stage(0x333333);
var renderer = PIXI.autoDetectRenderer(window.innerWidth, window.innerHeight);

var img = new Image();
img.src = 'image.png';

var bg = PIXI.Sprite.fromImage(img);
stage.addChild(bg);

var canvas = document.querySelector('#foreground');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var options = {
  penColor: 'rgba(255, 0, 0, .2)'
}
var signaturePad = new SignaturePad(canvas, options);

var texture = PIXI.Texture.fromCanvas(canvas);
var fg = new PIXI.Sprite(texture);
stage.addChild(fg);

// bg.mask = fg;

document.body.appendChild(renderer.view);
requestAnimFrame(animate);

function animate() {
  requestAnimFrame(animate);
  renderer.render(stage);
}
here’s my code
anyone has an idea ? :)
Chad Engler
@englercj
Oct 12 2015 22:35
A bunch of things look fishy, the first I'd that you are using PIXI. Stage, which likely means you are on v2. You should upgrade to v3
Also fromImage takes a string url to an image, not an image object.