Skip to content

Commit 0098129

Browse files
Merge pull request #88 from pixijs/dev
Support PixiJS v7
2 parents cc691df + cfe381e commit 0098129

30 files changed

+9627
-9508
lines changed

.eslintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build CI
2+
on:
3+
push:
4+
branches: [ '**' ]
5+
tags: [ '**' ]
6+
release:
7+
types: [ 'created' ]
8+
pull_request:
9+
branches: [ '**' ]
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Use Node.js 16.x
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 16
19+
- name: Install npm
20+
run: npm install -g npm@8
21+
- name: Install dependencies
22+
run: npm ci
23+
- name: Build
24+
run: npm run build
25+
- name: Documention
26+
run: npm run docs

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ docs/
2828
.idea
2929

3030
# tsc output
31-
compile
3231
dist
3332
lib
3433
index.d.ts
34+
35+
# webdoc
36+
example.api.json*

README.md

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# @pixi/layers - PixiJS Layers Kit
22

3-
[![Build](https://github.com/pixijs/layers/workflows/Build/badge.svg)](https://github.com/pixijs/layers/actions?query=workflow%3A%22Build%22) [![npm version](https://badge.fury.io/js/%40pixi%2Flayers.svg)](https://badge.fury.io/js/%40pixi%2Flayers)
3+
[![Build CI](https://github.com/pixijs/layers/actions/workflows/build.yml/badge.svg)](https://github.com/pixijs/layers/actions/workflows/build.yml) [![npm version](https://badge.fury.io/js/%40pixi%2Flayers.svg)](https://badge.fury.io/js/%40pixi%2Flayers)
44

55
This package provides an extension to scene tree - layers. These layers allows you to change
66
the rendering order of items in your scene without moving them around in your scene. It's like
77
{@link PIXI.DisplayObject#zIndex zIndex}, but supercharged.
88

9-
It has been ported to PixiJS 6 since @pixi/layers 1.0.0 (formerly pixi-layers).
9+
It has been ported to PixiJS 7 since @pixi/layers 2.0.0 (formerly pixi-layers).
1010

1111
**Nothing will work if you dont create Stage and set it as root. Please do it or read full explanation.**
1212

@@ -16,28 +16,21 @@ It has been ported to PixiJS 6 since @pixi/layers 1.0.0 (formerly pixi-layers).
1616
npm install --save @pixi/layers
1717
```
1818

19-
### Migration from v5
20-
21-
See [usage with canvas and particles](#usage-with-canvas-and-particles) part of this doc.
22-
23-
If you still work with PixiJS `v5` and prior - see README `pixi-v5` branch, or just use npm package `pixi-layers`
24-
2519
## Examples
2620

27-
* [Lighting example](https://pixijs.io/examples/#/plugin-layers/lighting.js)
28-
* [Z-order example](https://pixijs.io/examples/#/plugin-layers/zorder.js)
29-
* [Double buffering](http://pixijs.github.io/examples/#/layers/trail.js)
30-
* [Normals example - WORK IN PROGRESS](http://pixijs.github.io/examples/#/layers/normals.js)
31-
* [Normals with sorting - WORK IN PROGRESS](http://pixijs.github.io/examples/#/layers/normals.js)
21+
* [Blend Modes example](https://pixijs.io/layers/examples/blend-modes.html)
22+
* [Z-order example](https://pixijs.io/layers/examples/z-order.html)
23+
* [Double buffering](https://pixijs.io/layers/examples/trail.html)
24+
* [Bring To Top](https://pixijs.io/layers/examples/bring-to-top.html)
3225

3326
## Usage
3427

3528
{@link Layer} extends {@link PIXI.Container}:
3629

3730
```js
38-
import { Layer } from '@pixi/layers'
31+
import { Layer } from '@pixi/layers';
3932

40-
let layer = new Layer();
33+
const layer = new Layer();
4134
```
4235

4336
A DisplayObject/Container can be rendered inside its layer instead of direct parent
@@ -89,29 +82,29 @@ When you move a character with attached sprites from different layers to a new s
8982

9083
Instead, you can create a new display Group:
9184

92-
```
93-
let lightGroup = new Group();
85+
```js
86+
const lightGroup = new Group();
9487

9588
bunnySprite.parentGroup = lightGroup;
96-
let lightLayer = new Layer(lightGroup); // only one layer per stage can be bound to same group
89+
const lightLayer = new Layer(lightGroup); // only one layer per stage can be bound to same group
9790
```
9891

9992
Groups are working between different stages, so when you move bunny it will be rendered in its light layer.
10093

10194
Layer is representation of global Group in this particular stage.
10295

103-
## Vanilla JS, UMD build
96+
## Vanilla JS,
10497

105-
All pixiJS v6 plugins has special `umd` build suited for vanilla.
106-
Navigate `pixi-layers` npm package, take `dist/pixi-layers.umd.js` file.
98+
All PixiJS has a special bundle suited for vanilla JavaScript in the browser.
99+
Navigate `pixi-layers` npm package, take `dist/pixi-layers.js` file.
107100

108101
```html
109-
<script src='lib/pixi.js'></script>
110-
<script src='lib/pixi-layers.umd.js'></script>
102+
<script src="./pixi.min.js"></script>
103+
<script src="./pixi-layers.js"></script>
111104
```
112105

113106
```js
114-
let layer = new PIXI.display.Layer();
107+
const layer = new PIXI.layers.Layer();
115108
```
116109

117110
## Usage with canvas and particles
@@ -123,19 +116,19 @@ The important thing is to call it when you know that corresponding module is loa
123116
If you use `@pixi/canvas-renderer`
124117

125118
```js
126-
import * as PIXI from 'pixi.js-legacy';
119+
import { CanvasRenderer } from 'pixi.js-legacy';
127120
import { applyCanvasMixin } from '@pixi/layers';
128121

129-
applyCanvasMixin(PIXI.CanvasRenderer);
122+
applyCanvasMixin(CanvasRenderer);
130123
```
131124

132125
If you use `@pixi/particles`
133126

134127
```js
135-
import * as PIXI from 'pixi.js';
128+
import { ParticleContainer } from 'pixi.js';
136129
import { applyCanvasMixin } from '@pixi/layers';
137130

138-
applyParticleMixin(PIXI.ParticleContainer);
131+
applyParticleMixin(ParticleContainer);
139132
```
140133

141134
## Advanced sorting

api-extractor.json

Lines changed: 0 additions & 44 deletions
This file was deleted.

examples/assets/bunny.png

223 Bytes
Loading

examples/assets/bunny_blue.png

252 Bytes
Loading

examples/assets/bunny_green.png

206 Bytes
Loading

examples/assets/p2.jpg

12.3 KB
Loading

examples/blend-modes.html

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Blend Modes | PixiJS Lights Examples</title>
6+
<script src="https://pixijs.download/dev/pixi.min.js"></script>
7+
<script src="../dist/pixi-layers.js"></script>
8+
<link rel="stylesheet" href="style.css" />
9+
</head>
10+
<body>
11+
<h1>Blend Modes</h1>
12+
<script>
13+
const W = 800;
14+
const H = 600;
15+
const PAD = 80;
16+
const resolution = 1;
17+
const WIDTH = W / resolution;
18+
const HEIGHT = H / resolution;
19+
20+
const app = new PIXI.Application({
21+
width: WIDTH,
22+
height: HEIGHT,
23+
resolution,
24+
});
25+
document.body.appendChild(app.view);
26+
27+
// create the stage instead of container
28+
app.stage = new PIXI.layers.Stage();
29+
30+
const background = new PIXI.TilingSprite(
31+
PIXI.Texture.from('assets/p2.jpg'),
32+
WIDTH,
33+
HEIGHT,
34+
);
35+
app.stage.addChild(background);
36+
// make container for bunnies
37+
const bunnyWorld = new PIXI.Container();
38+
app.stage.addChild(bunnyWorld);
39+
40+
const lighting = new PIXI.layers.Layer();
41+
lighting.on('display', (element) => {
42+
element.blendMode = PIXI.BLEND_MODES.ADD;
43+
});
44+
lighting.useRenderTexture = true;
45+
lighting.clearColor = [0.5, 0.5, 0.5, 1]; // ambient gray
46+
47+
app.stage.addChild(lighting);
48+
49+
const lightingSprite = new PIXI.Sprite(lighting.getRenderTexture());
50+
lightingSprite.blendMode = PIXI.BLEND_MODES.MULTIPLY;
51+
52+
app.stage.addChild(lightingSprite);
53+
54+
const bunnyTexture = PIXI.Texture.from('assets/bunny.png');
55+
function updateBunny(bunny) {
56+
bunny.x += bunny.vx;
57+
bunny.y += bunny.vy;
58+
if (bunny.x > WIDTH + PAD) {
59+
bunny.x -= WIDTH + 2 * PAD;
60+
}
61+
if (bunny.x < -PAD) {
62+
bunny.x += WIDTH + 2 * PAD;
63+
}
64+
if (bunny.y > HEIGHT + PAD) {
65+
bunny.y -= HEIGHT + 2 * PAD;
66+
}
67+
if (bunny.y < -PAD) {
68+
bunny.y += HEIGHT + 2 * PAD;
69+
}
70+
}
71+
72+
function createBunny() {
73+
const bunny = new PIXI.Sprite(bunnyTexture);
74+
bunny.update = updateBunny;
75+
76+
const angle = Math.random() * Math.PI * 2;
77+
const speed = 200.0; // px per second
78+
bunny.vx = Math.cos(angle) * speed / 60.0;
79+
bunny.vy = Math.sin(angle) * speed / 60.0;
80+
bunny.position.set(Math.random() * WIDTH, Math.random() * HEIGHT);
81+
bunny.anchor.set(0.5, 0.5);
82+
83+
const lightbulb = new PIXI.Graphics();
84+
const rr = Math.random() * 0x80 | 0;
85+
const rg = Math.random() * 0x80 | 0;
86+
const rb = Math.random() * 0x80 | 0;
87+
const rad = 50 + Math.random() * 20;
88+
lightbulb.beginFill((rr << 16) + (rg << 8) + rb, 1.0);
89+
lightbulb.drawCircle(0, 0, rad);
90+
lightbulb.endFill();
91+
lightbulb.parentLayer = lighting;// <-- try comment it
92+
93+
bunny.addChild(lightbulb);
94+
95+
return bunny;
96+
}
97+
98+
for (let i = 0; i < 40; i++) {
99+
bunnyWorld.addChild(createBunny());
100+
}
101+
102+
app.ticker.add(() => {
103+
bunnyWorld.children.forEach(updateBunny);
104+
});
105+
</script>
106+
</html>

0 commit comments

Comments
 (0)