Sign in to follow this  
polansk1

Mask following player

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;   

Share this post


Link to post
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... 

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.