Jump to content

Mask following player


polansk1
 Share

Recommended Posts

Hi again! i will make a mask covering all canvas but my player, making a circle around him. And i will that circle follow the player all time. I found that code but i think its not working because it's Phaser2. How can i do that?

mask = game.add.graphics(0, 0);
    mask.beginFill(0xffffff);
    mask.drawCircle(100, 100, 100);
    fondo.mask = mask;
    fondo.mask = mask;   

Link to comment
Share on other sites

dont know how to define mask :S

I have a background (fondo) and a sprite (player). How i set the mask covering all background except player? 

I'm newbie in phaser sorry and it's difficult to learn for me because i dont have too many documentation for phaser3... 

Link to comment
Share on other sites

Ty man! i found it at end :D :

preload:

this.load.image('mask', 'img/mask1.png');

create:

spotlight = this.make.sprite({
        x: 400,
        y: 300,
        key: 'mask',
        add: false
    });

    background.mask = new Phaser.Display.Masks.BitmapMask(this, spotlight);

update: 

spotlight.x = player.x;
spotlight.y = player.y;

 

The problem with that is i have to apply the mask to all layers, if i only apply to one layer i see the other objects on top of the mask. If anyone know another way to apply the mask to all canvas at same time i will appreciate it :) but at the moment that it's ok im happy!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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