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, 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.
Rationale
I wanted to improve my work on yy-viewport with a complete rewrite of a viewport/2D camera for use with pixi.js. I added options that I need in my games, including edges that bounce, deceleration, and highly configurable options to tweak the feel of the viewport.
Simple Example
const Viewport = require('pixi-viewport')
const container = new PIXI.Container()
const viewport = new Viewport(container,
{
screenWidth: window.innerWidth,
screenHeight: window.innerHeight,
worldWidth: 1000,
worldHeight: 1000
})
viewport
.drag()
.pinch()
.wheel()
.decelerate()
.bounce()
viewport
.start()
Live Example
https://davidfig.github.io/pixi-viewport/
Installation
npm i pixi-viewport
API Reference
constructor(container, options)
resize(screenWidth, screenHeight, worldWidth, worldHeight)
get screenWidth()
get screenHeight()
get worldWidth()
get worldHeight()
toWorld()
toScreen()
get worldScreenWidth()
get worldScreenHeight()
get screenWorldWidth()
get screenWorldHeight()
get center()
moveCenter()
get corner()
moveCorner()
fitWidth(width, center)
fitHeight(height, center)
fitWorld(center)
fit(center)
snapZoom(options)
get right()
get left()
get top()
get bottom()
get dirty()
removePlugin(type)
pausePlugin(type)
resumePlugin(type)
drag()
clamp(options)
decelerate(options)
bounce(options)
pinch(options)
snap(x, y, options)
follow(target, options)
wheel(options)
clampZoom(options)
mouseEdges(options)
license
MIT License
(c) 2017 YOPEY YOPEY LLC by David Figatner