Jump to content

Some problems with simple mask


kentskyo
 Share

Recommended Posts

I'm missing something about getting a simple mask to work, would appreciate any clues...

var mask;
var img;

function preload() {
  game.load.image('back', 'backdrop.jpg');
}

function create() {
  img = game.add.image(game.world.centerX, game.world.centerY,'back').anchor.setTo(0.5);
  mask = game.add.graphics(0, 0);
  mask.beginFill(0xffffff);
  mask.drawCircle(game.world.centerX, game.world.centerY, 600);
  img.mask = mask;
}

Results in:

the entire background 800x800 image with a white circle on top (the mask)

Thanks!

jsfiddle here

2016-07-25_175412.png

Link to comment
Share on other sites

changing this

 img = game.add.image(game.world.centerX, game.world.centerY,'back').anchor.setTo(0.5);

to this:

 img = game.add.image(0,0, 'back');


allowed the mask to work, but there's something I don't understand about masks... do they assume the image masked is always at 0,0 in world coordinate space?

Link to comment
Share on other sites

Yup, a classic javascript coding error, in this case the setTo function returns a reference to the anchor point and not the phaser image you were expecting.

Is this the type or problem Typescript would have caught?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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