Jump to content

Passing Properties to children?


StudioMaker
 Share

Recommended Posts

Is there any built in system that would pass on attributes and properties to children for example inside of a container?

A bit like how html works if you have an element inside another, and for example make the element w 50, h 50, position: abs, right: 0, top: 0, the properties gets passed on to the children etc etc, i could make this myself but it would save some time if there already was something for it.

Link to comment
Share on other sites

First-class citizen of PixiJS tree is Transform. It has position, scale, rotation, pivot. Resulting matrix is passed down to children.

Width and height are by-products, they are calculated fields and if you set them - you can get in trouble if you dont read source code on how do they work (like in Adobe Flash).

If Pixi actually cared about layout, it wouldn't be a small rendering library. Its your job to implement it or find UI kits that support pixi.

There are so many ways to do that, usually people write their own systems. One of best UI's was pixi-ui - but its not ported to v5 yet, and it has almost no docs. It mirrors Unity UI. There are GUI systems that work with both pixi and phaser, I dont remember names nor links, please post them here if you find.

As if you need basic stuff just for a few elements - it always better to write your own. @jonforum knows many tricks, you can search and read his posts.

Its fine to post questions like that on forum, because you never know which things have standards in community and which ones people usually write on their own.

Edited by ivan.popelyshev
Link to comment
Share on other sites

well hum from what i understand, sorry if i'm wrong am not thats good like ivan in my english., so am not fully understand what your ask.
But a cool way to do this can be create a special container Class.

Maybe a good starting point would be to experiment with this kind of system in your project.
I have nothing come to my mind because I don't know the context of your project :)
Setter can be good idea or static methods utility with a pool, or simple methods .. use what you prefer work with.

class SpecialContainer extends PIXI.Container {
    constructor() {
        super()
    };

    set PROPRETIES(value) {
        this.properties = value;
        this.children.forEach((c)=>c.properties = value);
    }

    set SCALE(value) {// it just a very fast example!
        value = Array.isArray(value)?value:[value,value]
        this.scale.set(...value)
        this.children.forEach((c)=>c.scale.set(...value));
    }
};


Do not be shy to create your own class with your own needs.
Does that sound like with what you want? maybe share your code and context.

Edited by jonforum
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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