All Projects → davidfig → Pixi Viewport

davidfig / Pixi Viewport

Licence: mit
A highly configurable viewport/2D camera designed to work with pixi.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pixi Viewport

Zoom
Javascript library to do pinch zoom that preserves scale and rotation correctly.
Stars: ✭ 130 (-75.56%)
Mutual labels:  touch, zoom
React Fit To Viewport
Stars: ✭ 92 (-82.71%)
Mutual labels:  viewport, zoom
Pixi Cull
a library to visibly cull objects designed to work with pixi.js
Stars: ✭ 51 (-90.41%)
Mutual labels:  pixi, viewport
Chartjs Plugin Zoom
Zoom and pan plugin for Chart.js
Stars: ✭ 404 (-24.06%)
Mutual labels:  zoom
Notebook
my notebook 📒
Stars: ✭ 405 (-23.87%)
Mutual labels:  touch
D Zone
An ambient life simulation driven by user activity within a Discord server
Stars: ✭ 466 (-12.41%)
Mutual labels:  pixi
In View
Get notified when a DOM element enters or exits the viewport. 👀
Stars: ✭ 4,684 (+780.45%)
Mutual labels:  viewport
Pull To Reload
Pull to reload implementation for the web. Designed to work with both mobile and websites.
Stars: ✭ 396 (-25.56%)
Mutual labels:  touch
React Use Gesture
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
Stars: ✭ 5,704 (+972.18%)
Mutual labels:  zoom
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (-16.73%)
Mutual labels:  touch
Widgetcase
自定义控件模块库:各种风格的自定义控件,拿来就用,API文档详细,持续集成,长期维护,有问必答;
Stars: ✭ 440 (-17.29%)
Mutual labels:  touch
Creepyface
A JavaScript library that makes your face follow the pointer. 🤪🖱️👆
Stars: ✭ 412 (-22.56%)
Mutual labels:  touch
Yeetgif
gif effects CLI. single binary, no dependencies. linux, osx, windows. #1 workplace productivity booster. #yeetgif #eggplant #golang
Stars: ✭ 467 (-12.22%)
Mutual labels:  zoom
Vue Gallery
📷 Responsive and customizable image and video gallery, carousel and lightbox, optimized for both mobile and desktop web browsers.
Stars: ✭ 405 (-23.87%)
Mutual labels:  touch
React Fastclick
Fast Touch Events for React
Stars: ✭ 476 (-10.53%)
Mutual labels:  touch
React Socks
🎉 React library to render components only on specific viewports 🔥
Stars: ✭ 400 (-24.81%)
Mutual labels:  viewport
Vue Mq
📱 💻 Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue.
Stars: ✭ 474 (-10.9%)
Mutual labels:  viewport
Webosu
➤⓵ web rhythm game (unofficial osu!) http://osugame.online/
Stars: ✭ 434 (-18.42%)
Mutual labels:  pixi
Haptico
Haptico 📳 - easy to use haptic feedback generator with pattern-play support
Stars: ✭ 426 (-19.92%)
Mutual labels:  touch
Amplify
A tiny script allowing inline image zoom
Stars: ✭ 458 (-13.91%)
Mutual labels:  zoom

pixi-viewport

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, aniamte, snap to point, snap to zoom, clamping, bouncing on edges, and move on mouse edges. See live example to try out all of these features.

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

Migration from pixi-viewport v3 to v4

Viewport needs to be imported or required as follows:

import { Viewport } from 'pixi-viewport'

// or

const Viewport = 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)

Simple Example

import * as PIXI from 'pixi.js'
import { Viewport } from 'pixi-viewport'

const app = new PIXI.Application()
document.body.appendChild(app.view)

// create viewport
const viewport = new Viewport({
    screenWidth: window.innerWidth,
    screenHeight: window.innerHeight,
    worldWidth: 1000,
    worldHeight: 1000,

    interaction: app.renderer.plugins.interaction // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
})

// add the viewport to the stage
app.stage.addChild(viewport)

// activate plugins
viewport
    .drag()
    .pinch()
    .wheel()
    .decelerate()

// add a red box
const sprite = viewport.addChild(new PIXI.Sprite(PIXI.Texture.WHITE))
sprite.tint = 0xff0000
sprite.width = sprite.height = 100
sprite.position.set(100, 100)

Using commonjs:

const PIXI = require('pixi.js')
const Viewport = require('pixi-viewport').Viewport

// same code as above...

Live Example

https://davidfig.github.io/pixi-viewport/

API Documentation

https://davidfig.github.io/pixi-viewport/jsdoc/

Installation

yarn add pixi-viewport

or

npm i pixi-viewport

or grab the latest release and use it:

<script src="/directory-to-file/pixi.js"></script>
<script src="/directory-to-file/pixi-viewport.js"></script>
<!-- or <script type="module" src="/directory-to-file/pixi-viewport.es.js"></script> -->
<script>
    const Viewport = new Viewport.Viewport(options)
</script>

Build Examples

I've included a bunch of build examples in the docs/builds directory, including: browserify, rollup, standalone (e.g., cdn), standalone (pixi.js v4), and typescript. You can see the live demos at https://davidfig.github.io/pixi-viewport/builds/.

Tests

  1. Clone repository
  2. yarn install
  3. yarn test (for Mocha test code)
  4. yarn coverage (for Instanbul coverage)

Development Recipe

  1. clone repository
  2. yarn install
  3. yarn dev
  4. open browser to http://localhost:10001

PRs are more than welcome!

Other Libraries

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

license

MIT License (c) 2020 YOPEY YOPEY LLC by David Figatner ([email protected])

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].