Coder Social home page Coder Social logo

mask parent container about layers HOT 8 OPEN

pixijs avatar pixijs commented on July 25, 2024
mask parent container

from layers.

Comments (8)

ivanpopelyshev avatar ivanpopelyshev commented on July 25, 2024 1
        mask_d.width = d.width-42, mask_d.height = d.height-45;
        mask_n.width = d.width-42, mask_n.height = d.height-45;
        mask_d.position.set(42,45);
        mask_n.position.set(42,45);

I still dont understand why you use two masks there. One is enough. Mask is only a position+graphics

from layers.

ivanpopelyshev avatar ivanpopelyshev commented on July 25, 2024

that wont work because there's no way to distinguish whether you want a mask on parent or on each child individually. In this case mask can be applied only individually. But you can use the same mask if they are identical

from layers.

jonlepage avatar jonlepage commented on July 25, 2024

this give me some technical issue.
It work fine if i add mask for the background (x4)
My bg1 and bg2 are deformed with mouse move.
maskparentdn

But i have also container for items, and i would like to show all items in 1 page and use mask to scroll list.
But if i use this technique and mask all items, i drop to 5 fps!
And i cannot add items container to diffuse background , because it deformed with mouse.

The only thing i can see , it to split item to max (25) per page, and add a page selector to index new list each time.

Do you think it the only way, or you have a magic idea?

from layers.

jonlepage avatar jonlepage commented on July 25, 2024

this is was the original concept art, so mask background seem ok, but i can't not mask each items containers.
image

menueitems

from layers.

jonlepage avatar jonlepage commented on July 25, 2024

i just experimented something that's work
Am not sure if it a really good idea, but it work.
i remove the parentGroup , and add diffuse normal to the bg, and i will just need to remove the position update from parent.
i try with 250 items , and i get no lag or spike.

    for (let i=0, x = 250, y = 75, xx=0, l=maxGameItemsType; i<l; i++,x+=250) {
        const itemsFrame = new PIXI.Container();
        var d = new PIXI.Sprite(dataBase.textures.itemsFrame);
        var n = new PIXI.Sprite(dataBase.textures_n.itemsFrame_n);
            //d.parentGroup = PIXI.lights.diffuseGroup;
            //n.parentGroup = PIXI.lights.normalGroup;
            //itemsFrame.addChild(d,n);
// add to the mask background
            bg.children[0].addChild(d) // add to bg sprite diffuse
            bg.children[1].addChild(n) // add to bg sprite normal

from layers.

jonlepage avatar jonlepage commented on July 25, 2024

EUREKA !:)
first test work

maskdnwork

This give me a big headache!

It's a complex way to manage mask with diffuse and normal, by chance I need it only for rendering this menu.
So here how i proceed.

// create menu Items
_menu_items.prototype.initialize = function() {
    const dataBase = $Loader.Data2.menueItems;

    // contour du menue
    const frames = new PIXI.Container();
    var d = new PIXI.Sprite(dataBase.textures.menueItemFrame);
    var n = new PIXI.Sprite(dataBase.textures_n.menueItemFrame_n);
        d.parentGroup = PIXI.lights.diffuseGroup;
        n.parentGroup = PIXI.lights.normalGroup;
        frames.pivot.set(d.width/2,d.height/2);
    frames.addChild(d,n);
    
    //MASK FIXME: 
    const masked_d = new PIXI.Container(); // difuse menu mask limit 
    const masked_n = new PIXI.Container(); // normal menu mask limit
    masked_d.parentGroup = PIXI.lights.diffuseGroup;
    masked_n.parentGroup = PIXI.lights.normalGroup;
    const mask_d = new PIXI.Sprite(PIXI.Texture.WHITE);
    const mask_n = new PIXI.Sprite(PIXI.Texture.WHITE);
        mask_d.width = d.width-42, mask_d.height = d.height-45;
        mask_n.width = d.width-42, mask_n.height = d.height-45;
        mask_d.position.set(42,45);
        mask_n.position.set(42,45);
    masked_d.mask = masked_d.addChild(mask_d);
    masked_n.mask = masked_n.addChild(mask_n);

    // create x2 BG
    var d = new PIXI.Sprite(dataBase.textures.bgMaster);
    var n = new PIXI.Sprite(dataBase.textures_n.bgMaster_n);
        masked_d.addChild(d);
        masked_n.addChild(n);
    this.bgFX1 = {d,n}; // store for scope mouse FX deformation
    var d = new PIXI.Sprite(dataBase.textures.bgDiag);
    var n = new PIXI.Sprite(dataBase.textures_n.bgDiag_n);
        d.alpha = 0.2; n.alpha = 0.8;
        masked_d.addChild(d);
        masked_n.addChild(n);
    this.bgFX2 = {d,n}; // store for scope mouse FX deformation
    masked_d.pivot.set(d.width/2,d.height/2);
    masked_n.pivot.set(n.width/2,n.height/2);
   
    // build items test
    let maxGameItemsType = 120; //FIXME: add a game items limits
    let itemsFrames = []; // empty item frame avaible
    let bgTxtFocus = []; // empty item frame avaible
    for (let i=0, x = 250, y = 75, xx=0, l=maxGameItemsType; i<l; i++,x+=250) {
        // items frames containers
        var d = new PIXI.Sprite(dataBase.textures.itemsFrame);
        var n = new PIXI.Sprite(dataBase.textures_n.itemsFrame_n);
            d.position.set(x,y);
            n.position.set(x,y);
            masked_d.addChild(d);
            masked_n.addChild(n);
        itemsFrames.push({d,n});
        // text Background FX
        var d = new PIXI.Sprite(dataBase.textures.bgTxtFocus);
        var n = new PIXI.Sprite(dataBase.textures_n.bgTxtFocus_n);
            d.blendMode = 1;
            n.blendMode = 2;
            d.position.set(x,y);
            n.position.set(x,y);
            masked_d.addChild(d);
            masked_n.addChild(n);
            bgTxtFocus.push({d,n});
        xx++;
        if(xx===5){
            xx=0;
            x = 0;
            y+=87;
        }
    };
    // build filterBy
    const filterBy = new PIXI.Container();
    var d = new PIXI.Sprite(dataBase.textures.buttonFilterBy);
    var n = new PIXI.Sprite(dataBase.textures_n.buttonFilterBy_n);
        d.parentGroup = PIXI.lights.diffuseGroup;
        n.parentGroup = PIXI.lights.normalGroup;
    filterBy.addChild(d,n);
    filterBy.pivot.set(d.width/2,d.height/2);
    filterBy.position.set(760,15);
    filterBy.scale.set(0.9,0.9);

    
    this.parentGroup = $displayGroup.group[4];
    this.addChild(masked_d,masked_n,frames,filterBy);
    this.position.set(1050,680);
    //TODO: DELETE ME 
    setInterval((function(){ 
        this.bgFX1.d.position.set(($mouse.x/120)-20,($mouse.y/50)-20);
        this.bgFX2.d.position.set((($mouse.x/60)-20)*-1,(($mouse.y/45)-20)*-1);
        this.bgFX2.d.rotation = $mouse.x/70000;
        this.bgFX2.d.scale.x = 1-($mouse.x/100000);
       
    }).bind(this), 20);
};

from layers.

ivanpopelyshev avatar ivanpopelyshev commented on July 25, 2024

Actually, I think you need separate lights and diffuse and everything for that window. Double the groups. Add mouse light there too.

It requires understanding of how pixi-display and pixi-lights work, because I honestly didnt think that you add lights to windows too, and didnt take rectangular masks into account.

Well, actually, i have an idea how to fix that inside pixi-display :) I have to add extra field "groupMask" there and if there are multiple elements in the sorting sequence that have the same mask, mask will be applied only once.

from layers.

jonlepage avatar jonlepage commented on July 25, 2024

true, i don't know why but the first try was not work with x1 mask.
But now it work

    const masked_d = new PIXI.Container(); // difuse menu mask limit 
    const masked_n = new PIXI.Container(); // normal menu mask limit
        masked_d.parentGroup = PIXI.lights.diffuseGroup;
        masked_n.parentGroup = PIXI.lights.normalGroup;
    const mask_d = new PIXI.Sprite(PIXI.Texture.WHITE);
    //const mask_n = new PIXI.Sprite(PIXI.Texture.WHITE);
        mask_d.width = d.width-42, mask_d.height = d.height-45;
       // mask_n.width = d.width-42, mask_n.height = d.height-45;
        mask_d.position.set(42,45);
       // mask_n.position.set(42,45);
    masked_d.mask = masked_d.addChild(mask_d);
    masked_n.mask = mask_d;

Also If you add a groupMask, i will happy to use it :)
Because my code for now look very dirty.

from layers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.