
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
pixi-viewport
Advanced tools
A scrollable, zoomable stage for PIXI.js with pinch-to-zoom and accelerated swiping
A highly configurable viewport/2D camera designed to work with pixi.js
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.
const Viewport = require('pixi-viewport')
const container = new PIXI.Container()
const viewport = new Viewport(container)
https://davidfig.github.io/pixi-viewport/
npm i pixi-viewport
/**
* @param {PIXI.Container} container
* @param {number} screenWidth
* @param {number} screenHeight
* @param {PIXI.Rectangle} [worldBoundaries] - only needed for options.noOverDrag or options.bounce
* @param {object} [options]
*
* @param {boolean} [options.dragToMove]
*
* @param {boolean} [options.pinchToZoom] automatically turns on dragToMove
*
* @param {boolean} [options.noOverDrag] stops scroll beyond boundaries
* @param {boolean} [options.noOverDragX] stops scroll beyond X boundaries
* @param {boolean} [options.noOverDragY] stops scroll beyond Y boundaries
* @param {boolean} [options.noOverZoom] don't zoom smaller than screen size
* @param {object} [options.minZoom] {x, y} don't zoom smaller than world zoom x and/or y
* @param {object} [options.maxZoom] {x, y} don't zoom larger than world zoom x and/or y
*
* @param {boolean||object} [options.bounce] bounce back if pulled beyond boundaries
* @param {number} [options.bounce.time=150] number is milliseconds to bounce back
* @param {string} [options.bounce.ease=easeInOutSine] easing function to use when bouncing (see https://github.com/bcherny/penner)
*
* @param {boolean|object} [options.decelerate] decelerate after scrolling
* @param {number} [options.decelerate.friction=0.95] percent to decelerate after movement
* @param {number} [options.decelerate.frictionBounce=0.5] percent to decelerate after movement while inside a bounce
*
* @param {number} [options.minVelocity=0.01] minimum velocity before stopping deceleration
* @param {number} [options.threshold=10] minimum number of pixels to register a move
*
* @param {object} [options.snap] snap to location when not touched and not accelerating
* @param {PIXI.Point} [options.snap.point] point to snap to
* @param {number} [options.snap.speed=1] speed (in world pixels/ms) to snap to location
*
* @param {boolean|object} [options.lockOn] keep camera centered on an object
* @param {PIXI.DisplayObject|PIXI.Point} [options.lockOn.object] lock onto this object
* @param {PIXI.Rectangle} [options.lockOn.frame] stay within this frame (in screen coordinates)
*
* @param {boolean} [options.noUpdate] turn off internal calls to requestAnimationFrame() -- update() must be called manually on each loop
*
* @emit {click} function click(x, y) in world coordinates - this is called on the up() after a touch/mouse press that doesn't move the threshold pixels
*/
constructor(container, screenWidth, screenHeight, worldBoundaries, options)
/**
* @param {number} screenWidth
* @param {number} screenHeight
*/
resize(screenWidth, screenHeight)
/**
* change coordinates from screen to world
* @param {number|PIXI.Point} x
* @param {number} [y]
* @returns {PIXI.Point}
*/
toWorld()
/**
* change coordinates from world to screen
* @param {number|PIXI.Point} x
* @param {number} [y]
* @returns {PIXI.Point}
*/
toScreen()
/**
* call this manually if setting options.noUpdate = true
*/
update()
MIT License
(c) 2017 YOPEY YOPEY LLC by David Figatner
FAQs
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.
The npm package pixi-viewport receives a total of 22,505 weekly downloads. As such, pixi-viewport popularity was classified as popular.
We found that pixi-viewport demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.