Sign in to follow this  

Player health bar problem

Recommended Posts

I have a healthBar entity given by the code below which is in a separate file called health_bar_entity.js(melonjs code base)

game.HealthBar = me.Renderable.extend(
    init: function(hitPoints, maxHitPoints)
        this._super(me.Renderable, "init", [0, -24, 48, 6]);
        this.z = 100;
        this.hitPoints = hitPoints;
        this.maxHitPoints = maxHitPoints; = 1;
        this.currentHealth = 1;
        this.borderColor = '#000';
        this.alwaysUpdate = false;
    draw : function(renderer) 
           renderer.fillRect(this.pos.x, this.pos.y, this.width, this.height);
           renderer.fillRect(this.pos.x+1, this.pos.y+1, this.width-2, this.height-2);
              renderer.fillRect(this.pos.x+1, this.pos.y+1, this.width-2, this.height-2);
              renderer.fillRect(this.pos.x+1, this.pos.y+1, (this.width-2)*, this.height-2);
    update : function() 
           this.updateOnce = false;
           return true;
           return false; = this.currentHealth;
           return true;
    setHealth: function(hitPoints)
       this.currentHealth = hitPoints/this.maxHitPoints;
    setCurrentAnimation: function()
    //do nothing
    setAnimationFrame: function(blarg)
    //do nothing

and I want to add this to the player entity, but when I try to add to the player by using the code below, this is in the file game_player_entity.js(melonjs code base)

    this.player_health = 50;
    this.player_max_health = 100;
    this.healthBar = me.pool.pull("playerHealthbar", this.player_health, 
    console.log('health bar' + this.healthBar);

this.addChild(this.healthbar, 9);

it give me an error don't know whats going wrong have looked at the api and it seems that it should work


Edited by soulVampire
Refresh description

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.