Giter Site home page Giter Site logo

vimcaw / pixi-viewport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davidfig/pixi-viewport

1.0 1.0 0.0 21.52 MB

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

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

License: MIT License

JavaScript 99.47% HTML 0.53%

pixi-viewport's Introduction

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.

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)

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) 2019 YOPEY YOPEY LLC by David Figatner

pixi-viewport's People

Contributors

danieljoyce avatar davidfig avatar defaultsamson avatar ertrzyiks avatar fbessou avatar izumi-kun avatar kaflake avatar kalbert312 avatar lekzd avatar macropp avatar mcdenhoed avatar mrbuchmann avatar nikolas avatar omegablitz avatar richard-ejem avatar schekle avatar sransara avatar superschek avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.