pixi-viewport
A highly configurable viewport/2D camera designed to work with pixi.js.
Features include dragging, pinch-to-zoom, decelerated dragging, following target, snapping to point, clamping, bouncing on edges. See live example to try out 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
})
// activate plugins with the following plugins
viewport
.drag()
.pinch()
.wheel()
.decelerate()
.bounce()
// starts an automatic update loop for animations related to the viewport
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 center()
moveCenter()
get corner()
moveCorner()
fitWidth(width, center)
fitHeight(height, center)
fit(center)
get right()
get left()
get top()
get bottom()
removePlugin(type)
pausePlugin(type)
resumePlugin(type)
plugin(type)
drag()
clamp(direction)
decelerate(options)
bounce(options)
pinch(options)
hitArea(rect)
snap(x, y, options)
follow(target, options)
wheel(options)
clampZoom(options)
license
MIT License
(c) 2017 YOPEY YOPEY LLC by David Figatner