Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use sort for Group #20

Open
yyman001 opened this issue Dec 28, 2017 · 3 comments
Open

how to use sort for Group #20

yyman001 opened this issue Dec 28, 2017 · 3 comments

Comments

@yyman001
Copy link

thanks you ~
How to use sort for Group,
look this code,i use homepage demo code for my code,but it not to work...i don't understand。

//this demo for pixi.js homepage 
var greenGroup = new PIXI.display.Group(0, true);
greenGroup.on('sort', function (sprite) {
  //no work,sprite.zIndex is diy arrt
  sprite.zOrder = sprite.zIndex;
});

when i fix sprite.zIndex,sortfunction will auto run ? or i must be to run Group.sort()
this render who Container?? new PIXI.display.Stage() ornew Container()?

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Dec 28, 2017

make sure that pixi-layers works properly:

//global, for every stage, for every level, just global variables :) 
//You dont have to re-create them if you change level stage or whatever.
//groups are GLOBAL
var group1 = new PIXI.display.Group(0, false);
var group2 = new PIXI.display.Group(1, false);

//for current stage.
var layer1 = new PIXI.display.Layer(group1);
var layer2 = new PIXI.display.Layer(group2);
app.stage = new PIXI.display.Stage();
app.stage.addChild(layer1);
app.stage.addChild(layer2);

numbers 0,1 dont mean anything in current implementation. layer1 is the bottom one because we've added it first, and layer2 is the top because its second in the stage. Its natural pixi rendering order, there's nothing special yet.

For any element of the stage, you can specify if it needs to be rendered inside one of layers:

var stuff = new PIXI.Sprite(...);
app.stage.addChild(stuff); //renders after both layers
stuff.parentGroup = group1; //now it renders inside layer1, because its the layer in the stage corresponding to group1.

Stage update is called automagically from the Application, but if you dont use Application, please call it manually.

app.stage.updateStage();

To check if it works, please look at "layer1._sortedChildren" after render operation

If you enable sorting in the group, all elements will be sorted by zIndex asc and then by zOrder desc. You can use any of those props.

on('sort') happens before sorting, just to set zIndex or zOrder that you want to sort by.

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Dec 28, 2017

Please make a fiddle if something is not working.

Alternatively, you can try to make it work, spend several hours, and if its not working, then give me link to website, and then, when I have free time, I'll help you. After new year eve :)

@yyman001
Copy link
Author

@ivanpopelyshev thank you, I try it ,it working. I use vue.js for the components dev,i don't how to import it from ES6,and i use it look like,i copy code for my vue components,it work.
image
why oZindex more min this layer more tall, more big this layer more small,That's strange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants