Health bar Plugin doesn't upgrade its position

Recommended Posts


im trying to give any enemy in my game a health meter.  The problem is im using a Plugin and i cant upgrade the position of the Health bar. I want that the health bars move above any enemy.  Any idea how to fix it?

Im using this plugin:

Here is my Code for the enemys

var Enemy = function(game, x, y) {, game, x, y, 'atlas', 'sprite' + game.rnd.integerInRange(1, 10));
    this.anchor.setTo(0.5, 0.5);;
  this.enableBody = true;
  this.body.gravity.y = 400;
  this.physicsBodyType = Phaser.Physics.ARCADE;
  this.body.velocity.x = -100; = 100;
  this.maxHealth = 100;

  this.preloadBar = game.add.sprite(this.x, this.y, 'preloadBar');
  this.preloadBar.anchor.setTo(0.5, 0.5);;

  this.healthMeterBar =;

    this.update = function() {
    if(this.x <= 120){
    }, {
        y: this.y-45, x: this.x,
        width: 80, height: 10,
        foreground: '#01DF01',
        background: '#aa0000',
        alpha: 0.6

Enemy.prototype = Object.create(Phaser.Sprite.prototype);
Enemy.prototype.constructor = Enemy;


Share this post

Link to post
Share on other sites


See my files attached (, it works.

Just open the index.html file and drag the circle and the healtbar follow the circle.

Have a good day.


var config = {
	width: 800,
	height: 800,
	renderer: Phaser.CANVAS,
	antialias: true,
	multiTexture: true,
	state: {
		preload: create,
		update: update

let game = new Phaser.Game(config);
var circle;
var bar;

function create () { = true; = true;;

	circle =, 0);
	circle.beginFill(0xFF0000, 1);
	circle.drawCircle(300, 300, 100);

	//  Input Enable the sprite
	circle.inputEnabled = true;

	//  Allow dragging
	var bar_config = {
		width: 250,
		height: 40,
		x: 200,
		y: 400,
		bg: {
			color: '#Fff828'
		bar: {
			color: '#FEFF03'
		animationDuration: 200,
		flipped: false

	bar = new HealthBar(, bar_config);

	//here you discover the properties of  bar => HealthBar and you see sub-sprites like barSprite, bgSprite and others ...
        // in dev. tools on chrome and firefox also, just type bar in the console

function update () {

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.