Skip to content

Commit 83263c0

Browse files
authored
Merge pull request #501 from pixi-viewport/v6
V6
2 parents b601e21 + 0976580 commit 83263c0

21 files changed

+2087
-15738
lines changed

README.md

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# pixi-viewport
2+
23
A highly configurable viewport/2D camera designed to work with pixi.js.
34

45
Features include dragging, pinch-to-zoom, mouse wheel zooming, decelerated dragging, follow target, animate, snap to point, snap to zoom, clamping, bouncing on edges, and move on mouse edges. See the live examples below to try out all of these features.
56

67
All features are configurable and removable, so set up the viewport to be exactly what you need.
78

8-
## v5.2+
9-
Moves pixi-viewport to pixi.js v7.2+
9+
## v6.0.0
10+
11+
Moves pixi-viewport to pixi.js v8+ - sorry for the confusion.
12+
13+
## v5.0.2
14+
15+
Moves pixi-viewport to pixi.js v7.2+.
1016

1117
NOTE: there is a breaking change since in pixi.js v7.2 `interactive` (boolean) was deprecated in favor of `eventMode`.
1218

13-
## v5+
19+
## v5
20+
1421
Moves pixi-viewport to pixi.js v7 (thanks [@cuire](https://github.com/cuire)!).
1522

1623
NOTE: there is a breaking change since pixi-viewport moved to pixi's new event system. `options.interaction` is removed and you need pass `options.events` to the viewport for it to work properly. The events object can be found at pixi's `renderer.events` or `app.renderer.events`.
@@ -23,57 +30,57 @@ const viewport = new Viewport({ events: renderer.events });
2330
```
2431

2532
## v4.30.0+
33+
2634
This project was migrated to Typescript (thanks [@ShukantPal](https://github.com/ShukantPal)!). All functionality should be the same. The live Example has been updated.
2735

2836
## Live Examples
29-
* New: [https://pixi-viewport.github.io/pixi-viewport/](https://pixi-viewport.github.io/pixi-viewport/) (using [flems.io](https://flems.io))
30-
* Original: [https://pixi-viewport.github.io/pixi-viewport/original/](https://pixi-viewport.github.io/pixi-viewport/original)
37+
38+
- New: [https://pixi-viewport.github.io/pixi-viewport/](https://pixi-viewport.github.io/pixi-viewport/) (using [flems.io](https://flems.io))
39+
- Original: [https://pixi-viewport.github.io/pixi-viewport/original/](https://pixi-viewport.github.io/pixi-viewport/original)
3140

3241
## API Documentation
42+
3343
[https://pixi-viewport.github.io/pixi-viewport/jsdoc/](https://pixi-viewport.github.io/pixi-viewport/jsdoc/)
3444

3545
## Simple Example
46+
3647
```js
37-
import * as PIXI from 'pixi.js'
38-
import { Viewport } from 'pixi-viewport'
48+
import * as PIXI from "pixi.js";
49+
import { Viewport } from "pixi-viewport";
3950

4051
// or with require
4152
// const PIXI = require('pixi.js')
4253
// const Viewport = require('pixi-viewport').Viewport
4354

44-
const app = new PIXI.Application()
45-
document.body.appendChild(app.view)
55+
const app = new PIXI.Application();
56+
document.body.appendChild(app.view);
4657

4758
// create viewport
4859
const viewport = new Viewport({
49-
screenWidth: window.innerWidth,
50-
screenHeight: window.innerHeight,
51-
worldWidth: 1000,
52-
worldHeight: 1000,
53-
54-
events: app.renderer.events // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
55-
})
60+
screenWidth: window.innerWidth,
61+
screenHeight: window.innerHeight,
62+
worldWidth: 1000,
63+
worldHeight: 1000,
64+
events: app.renderer.events, // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
65+
});
5666

5767
// add the viewport to the stage
58-
app.stage.addChild(viewport)
68+
app.stage.addChild(viewport);
5969

6070
// activate plugins
61-
viewport
62-
.drag()
63-
.pinch()
64-
.wheel()
65-
.decelerate()
71+
viewport.drag().pinch().wheel().decelerate();
6672

6773
// add a red box
68-
const sprite = viewport.addChild(new PIXI.Sprite(PIXI.Texture.WHITE))
69-
sprite.tint = 0xff0000
70-
sprite.width = sprite.height = 100
71-
sprite.position.set(100, 100)
74+
const sprite = viewport.addChild(new PIXI.Sprite(PIXI.Texture.WHITE));
75+
sprite.tint = 0xff0000;
76+
sprite.width = sprite.height = 100;
77+
sprite.position.set(100, 100);
7278
```
7379

7480
## Installation
7581

7682
yarn add pixi-viewport
83+
7784
or
7885

7986
npm i pixi-viewport
@@ -85,32 +92,36 @@ or [grab the latest release](https://github.com/davidfig/pixi-viewport/releases/
8592
<script src="/directory-to-file/viewport.min.js"></script>
8693
<!-- or <script type="module" src="/directory-to-file/esm/viewport.es.js"></script> -->
8794
<script>
88-
const Viewport = new pixi_viewport.Viewport(options)
95+
const Viewport = new pixi_viewport.Viewport(options);
8996
</script>
9097
```
9198

9299
## Migration from pixi-viewport v3 to v4
100+
93101
Viewport needs to be imported or required as follows:
102+
94103
```js
95-
import { Viewport } from 'pixi-viewport'
104+
import { Viewport } from "pixi-viewport";
96105

97106
// or
98107

99-
const Viewport = require('pixi-viewport').Viewport
108+
const Viewport = require("pixi-viewport").Viewport;
100109
```
110+
101111
Plugins have been moved to their own object:
112+
102113
```js
103114
// viewport.pausePlugin('drag')
104-
viewport.plugins.pause('drag')
115+
viewport.plugins.pause("drag");
105116

106117
// viewport.resumePlugin('drag')
107-
viewport.plugins.resume('drag')
118+
viewport.plugins.resume("drag");
108119

109120
// viewport.removePlugin('drag')
110-
viewport.plugins.remove('drag')
121+
viewport.plugins.remove("drag");
111122

112123
// viewport.userPlugin('name', plugin, index)
113-
viewport.plugins.add('name', plugin, index)
124+
viewport.plugins.add("name", plugin, index);
114125
```
115126

116127
## Tests
@@ -130,11 +141,14 @@ viewport.plugins.add('name', plugin, index)
130141
PRs are more than welcome!
131142

132143
## Other Libraries
144+
133145
If you liked pixi-viewport, please try my other open source libraries:
134-
* [pixi-scrollbox](https://github.com/davidfig/pixi-scrollbox) - pixi.js scrollbox: a masked box that can scroll vertically or horizontally with scrollbars (uses pixi-viewport)
135-
* [pixi-ease](https://github.com/davidfig/pixi-ease) - pixi.js animation library using easing functions
136-
* [intersects](https://github.com/davidfig/intersects) - a simple collection of 2d collision/intersects functions. Supports points, circles, lines, axis-aligned boxes, and polygons
146+
147+
- [pixi-scrollbox](https://github.com/davidfig/pixi-scrollbox) - pixi.js scrollbox: a masked box that can scroll vertically or horizontally with scrollbars (uses pixi-viewport)
148+
- [pixi-ease](https://github.com/davidfig/pixi-ease) - pixi.js animation library using easing functions
149+
- [intersects](https://github.com/davidfig/intersects) - a simple collection of 2d collision/intersects functions. Supports points, circles, lines, axis-aligned boxes, and polygons
137150

138151
## license
152+
139153
MIT License
140154
(c) 2024 [YOPEY YOPEY LLC](https://yopeyopey.com/) by David Figatner ([email protected])

0 commit comments

Comments
 (0)