- Notifications
You must be signed in to change notification settings - Fork185
A highly configurable viewport/2D camera designed to work with pixi.js
License
pixijs-userland/pixi-viewport
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A highly configurable viewport/2D camera designed to work with pixi.js.
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.
All features are configurable and removable, so set up the viewport to be exactly what you need.
Moves pixi-viewport to pixi.js v8+ - sorry for the confusion.
Moves pixi-viewport to pixi.js v7.2+.
NOTE: there is a breaking change since in pixi.js v7.2interactive (boolean) was deprecated in favor ofeventMode.
Moves pixi-viewport to pixi.js v7 (thanks@cuire!).
NOTE: there is a breaking change since pixi-viewport moved to pixi's new event system.options.interaction is removed and you need passoptions.events to the viewport for it to work properly. The events object can be found at pixi'srenderer.events orapp.renderer.events.
constviewport=newViewport({events:renderer.events});// or// const viewport = new Viewport({ events: app.renderer.events });
This project was migrated to Typescript (thanks@ShukantPal!). All functionality should be the same. The live Example has been updated.
- New:https://viewport.pixijs.io/ (usingflems.io)
- Original:https://viewport.pixijs.io/original/
https://viewport.pixijs.io/jsdoc/
import*asPIXIfrom"pixi.js";import{Viewport}from"pixi-viewport";// or with require// const PIXI = require('pixi.js')// const Viewport = require('pixi-viewport').Viewportconstapp=newPIXI.Application();document.body.appendChild(app.view);// create viewportconstviewport=newViewport({screenWidth:window.innerWidth,screenHeight:window.innerHeight,worldWidth:1000,worldHeight:1000,events:app.renderer.events,// the interaction module is important for wheel to work properly when renderer.view is placed or scaled});// add the viewport to the stageapp.stage.addChild(viewport);// activate pluginsviewport.drag().pinch().wheel().decelerate();// add a red boxconstsprite=viewport.addChild(newPIXI.Sprite(PIXI.Texture.WHITE));sprite.tint=0xff0000;sprite.width=sprite.height=100;sprite.position.set(100,100);
yarn add pixi-viewportor
npm i pixi-viewportorgrab the latest release and use it:
<scriptsrc="/directory-to-file/pixi.js"></script><scriptsrc="/directory-to-file/viewport.min.js"></script><!-- or <script type="module" src="/directory-to-file/esm/viewport.es.js"></script> --><script>constViewport=newpixi_viewport.Viewport(options);</script>
Viewport needs to be imported or required as follows:
import{Viewport}from"pixi-viewport";// orconstViewport=require("pixi-viewport").Viewport;
Plugins have been moved to their own object:
// viewport.pausePlugin('drag')viewport.plugins.pause("drag");// viewport.resumePlugin('drag')viewport.plugins.resume("drag");// viewport.removePlugin('drag')viewport.plugins.remove("drag");// viewport.userPlugin('name', plugin, index)viewport.plugins.add("name",plugin,index);
- Clone repository
- yarn install
- yarn test (for Mocha test code)
- yarn coverage (for Instanbul coverage)
- clone repository
- yarn install
- yarn dev
- open browser tohttp://localhost:5173
PRs are more than welcome!
If you liked pixi-viewport, please try my other open source libraries:
- pixi-scrollbox - pixi.js scrollbox: a masked box that can scroll vertically or horizontally with scrollbars (uses pixi-viewport)
- pixi-ease - pixi.js animation library using easing functions
- intersects - a simple collection of 2d collision/intersects functions. Supports points, circles, lines, axis-aligned boxes, and polygons
MIT License(c) 2024YOPEY YOPEY LLC by David Figatner (david@yopeyopey.com)
About
A highly configurable viewport/2D camera designed to work with pixi.js
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.