Skip to content

MasatoMakino/pixijs-basic-scrollbar

Repository files navigation

pixijs-basic-scrollbar

Scrollbar modules for pixi.js

MIT License CI Test Coverage Maintainability

ReadMe Card

Demo

Demo Page

Getting Started

Install

npm install @masatomakino/pixijs-basic-scrollbar --save-dev

pixijs-basic-scrollbar depend on pixi.js and @tweenjs/tween.js

Import

pixijs-basic-scrollbar is composed of ES6 modules and TypeScript d.ts files.

At first, import classes.

import { SliderView } from "@masatomakino/pixijs-basic-scrollbar";

Add to stage

const slider = new SliderView({
  base: new Graphics(...),
  bar: new Graphics(...),
  button: new Graphics(...),
  mask: new Graphics(...),
  minPosition: 0,
  maxPosition: 320, //slider width
  rate: 0.0,
  canvas : app.canvas // Option : global drag on canvas element
});

slider.on("slider_change", e => {
  console.log(e.rate);
});
stage.addChild(slider);

API documents

remove from stage

slider.dispose();

If you want to remove the slider, call the dispose method. SliderView has a reference to PixiJS's ticker, so it is necessary to call the dispose method to remove the reference.

Option : global drag on canvas element

Since v7, pixi.js does not get pointer events where nothing is drawn. Give a canvas element as an argument so that dragging continues outside the slider.

const slider = new SliderView(
  ...,
  canvas: app.canvas
});