Advertisement
Guest User

Untitled

a guest
Jun 18th, 2020
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is demo of pixi-layers.js, https://github.com/pixijs/pixi-layers
  2. // Drag the rabbits to understand what's going on
  3.  
  4. const app = new PIXI.Application({ backgroundColor: 0x1099bb });
  5. document.body.appendChild(app.view);
  6.  
  7. const textureGreen = PIXI.Texture.from('examples/assets/bunny_green.png');
  8. const textureBlue = PIXI.Texture.from('examples/assets/bunny_blue.png');
  9.  
  10. let blue = new PIXI.Container();
  11. let green = new PIXI.Container();
  12.  
  13. app.stage = new PIXI.display.Stage();
  14. app.stage.sortableChildren = true;
  15.  
  16. const defaultGroup = new PIXI.display.Group(5, false);
  17. app.stage.addChild(new PIXI.display.Layer(defaultGroup), blue, green);
  18.  
  19. for (let i = 0; i < 15; i++) {
  20.     const bunny = new PIXI.Sprite(textureGreen);
  21.     bunny.width = 50;
  22.     bunny.height = 50;
  23.     bunny.position.set(100 + 20 * i, 100 + 20 * i);
  24.     bunny.anchor.set(0.5);
  25.  
  26.     bunny.zOrder = 2;
  27.     bunny.zIndex = 2;
  28.     bunny.parentGroup = defaultGroup;
  29.     green.addChild(bunny);
  30. }
  31.  
  32. for (let i = 9; i >= 0; i--) {
  33.     const bunny = new PIXI.Sprite(textureBlue);
  34.     bunny.width = 50;
  35.     bunny.height = 50;
  36.     bunny.position.set(100 + 20 * i, 150 + 20 * i);
  37.     bunny.anchor.set(0.5)
  38.  
  39.     bunny.zOrder = 1;
  40.     bunny.zIndex = 1;
  41.     bunny.parentGroup = defaultGroup;
  42.  
  43.     if (i == 9) {
  44.       bunny.tint = 0xFF0000;
  45.       bunny.zOrder = 3;
  46.       bunny.zIndex = 3;
  47.     }
  48.  
  49.     blue.addChild(bunny);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement