Advertisement
nPhoenix

Phaser Mask

Feb 12th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var config = {
  2.     type: Phaser.AUTO,
  3.     width: 800,
  4.     height: 600,
  5.     parent: 'phaser-example',
  6.     scene: {
  7.         preload: preload,
  8.         create: create
  9.     }
  10. };
  11.  
  12. var game = new Phaser.Game(config);
  13.  
  14. function preload ()
  15. {
  16.     this.load.image('pic', 'assets/pics/rick-and-morty-by-sawuinhaff-da64e7y.png');
  17. }
  18.  
  19. function create ()
  20. {
  21.  
  22.     this.cameras.main.setBackgroundColor(0x63F6F7);
  23.  
  24.     var image = this.add.image(400, 300, 'pic');
  25.  
  26.  
  27.  
  28.     var shape = this.make.graphics();
  29.  
  30.     //  Create a hash shape Graphics object
  31.     shape.fillStyle(0xffffff);
  32.  
  33.     //shape.slice(400, 300, 200, Phaser.Math.DegToRad(360), 0, true);
  34.  
  35.     shape.fillCircleShape({x: 200, y: 200, radius: 100});
  36.     shape.fillCircleShape({x: 500, y: 200, radius: 100});
  37.  
  38.     shape.fillPath();
  39.  
  40.     var mask = shape.createGeometryMask();
  41.  
  42.     image.setMask(mask);
  43.     image.setMask(mask);
  44.  
  45.     image.mask.invertAlpha = true;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement