Git Product home page Git Product logo

phaser.healthbar's Introduction

Phaser.Healthbar

An attempt to create a simple and customizable healthbar for Phaser.js games.

I made a tutorial in French that explain how to create this health bar from scratch, you can check it out here.

Demo

Demo

Usage

1 - Import HealthBar file

If you are using a CommonJS implementation (Browserify) :

var HealthBar = require('path/to/HealthBar.js');

if not, just include the HealthBar.standalone.js in the html file. example :

<script src="path/to/HealthBar.standalone.js"></script>

2 - create a healthBar :

in the game/state create function instantiate a Healthbar like this:

create: function() {	
	var barConfig = {x: 200, y: 100};
	this.myHealthBar = new HealthBar(this.game, barConfig);
}

Configuration

  • width
  • height
  • x: initial x position
  • y: initial y position
  • bg.color: background color
  • bar.color: color of the actual bar
  • animationDuration: control the animation when the bar value is changed
  • flipped: if true the bar will change size from left to right

this is the default configuration :

{
    width: 250,
    height: 40,
    x: 0,
    y: 0,
    bg: {
      color: '#651828'
    },
    bar: {
      color: '#FEFF03'
    },
    animationDuration: 200,
    flipped: false
  };

Methods

setPercent(value):

set the width of the bar to the passed percentage value.

example:

 this.myHealthBar = new HealthBar(this.game, {x: 200, y: 200, width: 120});

 // the width will be set to 50% of the actual size so the new value will be 60
 this.myHealthBar.setPercent(50); 

setPosition(x, y):

change the position of the bar to the provided coordinates.

phaser.healthbar's People

Contributors

bmarwane 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.