samedi 1 mai 2021

how to make pixi js mask filter respond to touch on mobile view as it does to pointer move in desktop view?

I want the flash light effect to follow mobile touch events in pixi js

I am trying to make the pixijs mask filter responsive as the flash light effect follows the mouse pointer , so i need to make it follow the touch events.Here's the link of the effect https://pixijs.io/examples/#/masks/filter.js

const app = new PIXI.Application();
document.querySelector('#landing').appendChild(app.view);

// Inner radius of the circle
const radius = 90;

// The blur amount
const blurSize = 52;

app.loader.add('landing', './imgs/bg.png');
app.loader.load(setup);

function setup(loader, resources) {
    const background = new PIXI.Sprite(resources.landing.texture);
    app.stage.addChild(background);
    background.width = app.screen.width;
    background.height = app.screen.height;

    const circle = new PIXI.Graphics()
        .beginFill(0xFF0000)
        .drawCircle(radius + blurSize, radius + blurSize, radius)
        .endFill();
    circle.filters = [new PIXI.filters.BlurFilter(blurSize)];

    const bounds = new PIXI.Rectangle(0, 0, (radius + blurSize) * 2, (radius + blurSize) * 2);
    const texture = app.renderer.generateTexture(circle, PIXI.SCALE_MODES.NEAREST, 1, bounds);
    const focus = new PIXI.Sprite(texture);

    app.stage.addChild(focus);
    background.mask = focus;

    app.stage.interactive = true;
    app.stage.on('mousemove', pointerMove);
    
    

    function pointerMove(event) {
        focus.position.x = event.data.global.x - focus.width / 2;
        focus.position.y = event.data.global.y - focus.height / 2;
    }

  
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.3.7/pixi.min.js"></script>



Aucun commentaire:

Enregistrer un commentaire