1.0.6 • Published 3 years ago

phaser3-plugin-easyprogressbar v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

phaser3-plugin-easyprogressbar

This is a phaser 3 plugin for creating easy to use and beautiful progressbars. Easy progressbars support:

  • Horizontal and vertical layout
  • Forward and backward progress
  • Flat and shiny design
  • Rounded progressbars
  • Customizable progress text
  • Adding and styling indicators
  • Animating progress

npm.io

Usage

import 'phaser';
import EasyProgressbarPlugin from 'phaser3-plugin-easyprogressbar';

const game = new Phaser.Game({
  width: 1024,
  height: 768,
  backgroundColor: 0xffffff,
  scale: {
    mode: Phaser.Scale.FIT,
    autoCenter: Phaser.Scale.CENTER_BOTH
  },
  scene: {
    create: create,
  },
  plugins: {
    global: [{
      key: 'EasyProgressbarPlugin',
      plugin: EasyProgressbarPlugin,
      start: true
    }]
  }
});

function create() {
  this.add.easyProgressbar(100, 100, 200, 48, {
    color: 0xf7cf57,
    padding: 3,
    radius: 3,
    progress: 1,
    text: {
      enabled: true,
      format: progress => `XP: ${(progress * 100).toFixed(0)}%`,
      origin: {
        x: 0.5,
        y: 0.5
      },
      align: {
        x: 'center',
        y: 'start'
      },
      style: {
        fontSize: '24px',
        stroke: '#000000',
        strokeThickness: 4,
        shadow: {
          offsetX: 2,
          offsetY: 2,
          color: '#000000',
          blur: 4,
          stroke: true,
          fill: true
        }
      }
    }
  });
}

API

// initialize plugin ...
// this.add.easyProgressbar(x, y, width, height, options)
const progressBar = this.add.easyProgressbar(0, 0, 100, 50, {});

Options can be as follows:

NameExplanationExampleDefault
progressThe initial progress of the progress bar. Must be float between 0 and 10.51
orientationOrientation of the progressbar. Can either be horizontal or verticalhorizontalhorizontal
reverseBoolean that indicates whether the progressbar operates forward or backwards. Also depends on the orientation. Forward direction for horizonal is from left to right. Forward direction for vertical is from top to bottom. If set to true it reverts the direction (right to left and bottom to top).truefalse
radiusThe radius of the progress bar corners. Maximum value is half of the width and height respectively based on orientation50
backgroundColorThe background color of the progress bar0xffffff0x000000
backgroundAlphaThe background alpha of the progress bar0.50.5
colorThe foreground color of the progressbar0xff00000xffffff
flatBoolean that indicates, whether the progressbar has some color highlights (false) or not (true)falsefalse
indicators.enabledBoolean that indicates whether indicators are drawn or not.truefalse
indicators.colorThe color of the indicators.0xffffff0x000000
indicators.alphaThe alpha of the indicators0.50.1
indicators.sizeThe width or height of the indicators depending on orientation52
indicators.distanceThe distance between indicators in percent of width or height of progressbar depending on orientation0.10.1
text.enabledBoolean that indicates whether progress text should be drawntruefalse
text.stylePhaser 3 compatible text style{}false
text.formatFunction that takes progress as first parameter and should return a stringprogress => (progress * 100).toFixed(0)progress => progress
text.origin.xThe x origin of the text0.50.5
text.origin.yThe y origin of the text0.50.5
text.align.xThe horizontal alignment of the text within the progressbar. Must be either start, center or endendcenter
text.align.yThe vertical alignment of the text within the progressbar. Must be either start, center or endendcenter
text.paddingThe padding of the foreground progressbar to its background25
const progressBar = this.add.easyProgressbar(0, 0, 100, 50, options);

// without animation
progressBar.setProgress(0.2);

// with animation
progressBar.setProgress(0.8, true);

Installation

npm i phaser3-plugin-easyprogressbar

Alternatively you can grab the latest distributed version directly from github via: https://raw.githubusercontent.com/dasheck0/phaser3-plugin-easyprogressbar/master/dist/EasyProgressbarPlugin.js

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dasheck0/phaser3-plugin-easyprogressbar/pulls. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

MIT License

Copyright (c) 2019 Stefan Neidig

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago