see IViewportOptions; events (pixi's app.renderer.events) is
required for input
ReadonlyinputOptionallastOptionalmovingFlags whether the viewport is being panned
ReadonlyoptionsThe options passed when creating this viewport, merged with the default values
ReadonlypluginsUse this to add user plugins or access existing plugins (e.g., to pause, resume, or remove them)
Number of pixels to move to trigger an input event (e.g., drag, pinch) or disable a clicked event
OptionalzoomingFlags whether the viewport zoom is being changed.
World coordinates of the bottom edge of the screen
Determines whether the viewport is dirty (i.e., needs to be rendered to the screen because of a change)
World coordinates of the left edge of the screen
Pause viewport (including animation updates such as decelerate)
World coordinates of the right edge of the screen
Changes scale of viewport and maintains center of viewport
Get how many world pixels fit on screen's height
Get how many world pixels fit in screen's width
World height in screen coordinates
World width in screen coordinates
World coordinates of the top edge of the screen
World height, in pixels
Screen height in world coordinates
Screen width in world coordinates
World width, in pixels
Animate the position and/or scale of the viewport To set the zoom level, use: (1) scale, (2) scaleX and scaleY, or (3) width and/or height
this
Bounce on borders NOTES: screenWidth, screenHeight, worldWidth, and worldHeight needs to be set for this to work properly fires 'moved', 'bounce-x-start', 'bounce-y-start', 'bounce-x-end', and 'bounce-y-end' events
Optionaloptions: IBounceOptions
options, see IBounceOptions
this
Clamp to world boundaries or other provided boundaries There are three ways to clamp:
Underflow determines what happens when the world is smaller than the viewport
NOTES: clamp is disabled if called with no options; use { direction: 'all' } for all edge clamping screenWidth, screenHeight, worldWidth, and worldHeight needs to be set for this to work properly
Optionaloptions: IClampOptions
options, see IClampOptions
this
Enable clamping of zoom to constraints
The minWidth/Height settings are how small the world can get (as it would appear on the screen) before clamping. The maxWidth/maxHeight is how larger the world can scale (as it would appear on the screen) before clamping.
For example, if you have a world size of 1000 x 1000 and a screen size of 100 x 100, if you set minWidth/Height = 100 then the world will not be able to zoom smaller than the screen size (ie, zooming out so it appears smaller than the screen). Similarly, if you set maxWidth/Height = 100 the world will not be able to zoom larger than the screen size (ie, zooming in so it appears larger than the screen).
Optionaloptions: IClampZoomOptions
options, see IClampZoomOptions
this
Decelerate after a move
NOTE: this fires 'moved' event during deceleration
Optionaloptions: IDecelerateOptions
options, see IDecelerateOptions
this
Overrides PIXI.Container's destroy to also remove the 'wheel' and PIXI.Ticker listeners
Optionaloptions: DestroyOptionsEnable one-finger touch to drag
NOTE: if you expect users to use right-click dragging, you should enable viewport.options.disableOnContextMenu
to avoid the context menu popping up on each right-click drag.
Optionaloptions: IDragOptions
options, see IDragOptions
this
Scroll viewport when the mouse is near one of the edges or outside a radius from the center of the screen.
Replaces Viewport.mouseEdges: speed is in screen pixels per second, so scrolling is the same at every
zoom level and frame rate.
NOTES: fires 'moved', 'edge-scroll-start', and 'edge-scroll-end' events
Optionaloptions: IEdgeScrollOptions
options, see IEdgeScrollOptions
this
Move the viewport so the bounding box is visible
left
top
OptionalresizeToFit: boolean
Resize the viewport so the box fits within the viewport
Finds the scale value that fits the larger of a world width and world height on the screen does not change the viewport (use fit... to change)
in world pixels
in world pixels
scale
Finds the scale value that fits the smaller of a world width and world height on the screen does not change the viewport (use fit... to change)
in world pixels
in world pixels
scale
Finds the scale value that fits a world height on the screens does not change the viewport (use fit... to change)
Height in world pixels
Find the scale value that fits a world width on the screen does not change the viewport (use fit... to change)
Width in world pixels
Change zoom so it fits the size or the entire world in the viewport
Optionalcenter: boolean
maintain the same center of the screen after zoom
Optionalwidth: number = ...
desired width
Optionalheight: number = ...
desired height
this
Change zoom so the height fits in the viewport
Optionalheight: number = ...
in world coordinates
Optionalcenter: boolean
maintain the same center of the screen after zoom
OptionalscaleX: boolean = true
whether to set scaleX = scaleY
OptionalnoClamp: boolean
whether to disable clamp-zoom
this
Change zoom so the width fits in the viewport
width in world coordinates
Optionalcenter: boolean
maintain the same center
whether to set scaleY=scaleX
OptionalnoClamp: boolean
whether to disable clamp-zoom
this
Change zoom so it fits the entire world in the viewport
Optionalcenter: boolean
maintain the same center of the screen after zoom
this
Follow a target
NOTES:
uses the (x, y) as the center to follow; for PIXI.Sprite to work properly, use sprite.anchor.set(0.5)
options.acceleration is not perfect as it doesn't know the velocity of the target. It adds acceleration
to the start of movement and deceleration to the end of movement when the target is stopped.
To cancel the follow, use: viewport.plugins.remove('follow')
to follow
Optionaloptions: IFollowOptions
options, see IFollowOptions
this
Scroll viewport when mouse hovers near one of the edges or radius-distance from center of screen.
NOTES: fires 'moved' event; there's a known bug where the mouseEdges does not work properly with "windowed" viewports
Optionaloptions: IMouseEdgesOptions
options, see IMouseEdgesOptions
use Viewport.edgeScroll instead: its speed is in screen pixels per second, while
mouseEdges' speed scrolls by speed * speed * 0.06 world pixels per frame (so it changes with zoom and frame rate).
mouseEdges keeps its current behavior for compatibility.
Move Viewport's top-left corner; also clamps and resets decelerate and bounce (as needed)
Is container out of world bounds
Enable pinch to zoom and two-finger touch to drag
Optionaloptions: IPinchOptions
options, see IPinchOptions
this
Use this to set screen and world sizes, needed for pinch/wheel/clamp/bounce.
defaults to window.innerWidth
defaults to window.innerHeight
OptionalworldWidth: numberOptionalworldHeight: numberZoom viewport to specific value.
value (e.g., 1 would be 100%, 0.25 would be 25%)
Optionalcenter: boolean
maintain the same center of the screen after zoom
this
Snap to a point
Optionaloptions: ISnapOptions
options, see ISnapOptions
this
Update viewport on each frame.
By default, you do not need to call this unless you set options.noTicker=true.
time in milliseconds since last update
Zoom using mouse wheel
NOTE: the default event listener for 'wheel' event is the options.events.domElement.
Optionaloptions: IWheelOptions
options, see IWheelOptions
this
Zoom viewport by increasing/decreasing width by a certain number of pixels.
in pixels
Optionalcenter: boolean
maintain the same center of the screen after zoom
this
Zoom viewport by a certain percent (in both x and y direction).
change (e.g., 0.25 would increase a starting scale of 1.0 to 1.25)
Optionalcenter: boolean
maintain the same center of the screen after zoom
this
A Container that acts as a 2D camera: add your world to it, then turn on plugins for the interactions you want (drag, pinch, wheel, clamp, and so on).
Plugins always run in a fixed order, whatever order you add them in. Use Viewport.plugins to pause, resume, or remove them, or to add your own Plugin.
Events
Listen with
viewport.on(name, callback). These are in addition to pixi's own Container events.clickeddrag-start,drag-endpinch-start,pinch-endViewportwheel-startwheel-scrollViewportwheel: true)snap-start,snap-endViewportsnap-zoom-start,snap-zoom-endViewportbounce-x-start,bounce-x-end,bounce-y-start,bounce-y-endViewportedge-scroll-start,edge-scroll-endViewportmouse-edge-start,mouse-edge-endViewportanimate-endViewportmovedzoomedmoved-end,zoomed-endViewportframe-endViewportplugin-removestring(plugin name)Inherited Container members aren't listed here; see pixi's documentation.